Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: make typed useRoute(currentRouteName) return children route types as well #2475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
posva merged 10 commits into vuejs:main from Anoesj:feat/typed-use-route-with-children
Apr 25, 2025

Conversation

@Anoesj
Copy link
Contributor

@Anoesj Anoesj commented Mar 13, 2025
edited
Loading

In an app (with a typed router) where route /a/b is a child of route /a, this makes useRoute('/a') return RouteLocationNormalizedLoadedTyped<RouteNamedMap, "/a"> | RouteLocationNormalizedLoadedTyped<RouteNamedMap, "/a/b">.

It works in a recursive manner, so whenever route /a/b/c is added as a child of /a/b, useRoute('/a') will return RouteLocationNormalizedLoadedTyped<RouteNamedMap, "/a"> | RouteLocationNormalizedLoadedTyped<RouteNamedMap, "/a/b"> | RouteLocationNormalizedLoadedTyped<RouteNamedMap, "/a/b/c">`.

Of course useRoute('/a/b/c') will only return RouteLocationNormalizedLoadedTyped<RouteNamedMap, "/a/b/c">.

Note

This PR is intended to be paired with the following unplugin-vue-router PR: posva/unplugin-vue-router#602
That PR changes the DTS generation to include RouteMeta and a union of the children route's names as generics to every RouteRecordInfo type.

Copy link

netlify bot commented Mar 13, 2025
edited
Loading

Deploy Preview for vue-router canceled.

Name Link
🔨 Latest commit bc9cea2
🔍 Latest deploy log https://app.netlify.com/sites/vue-router/deploys/680b409cc34892000806e8c2

Copy link

pkg-pr-new bot commented Apr 23, 2025
edited
Loading

Open in StackBlitz

npm i https://pkg.pr.new/vue-router@2475

commit: bc9cea2

Copy link

codecov bot commented Apr 23, 2025
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.89%. Comparing base (3753ede) to head (bc9cea2).
Report is 15 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@
## main #2475 +/- ##
=======================================
 Coverage 94.89% 94.89% 
=======================================
 Files 34 34 
 Lines 2998 2998 
 Branches 845 845 
=======================================
 Hits 2845 2845 
 Misses 150 150 
 Partials 3 3 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@posva posva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ready!

Anoesj reacted with heart emoji BobbieGoede reacted with eyes emoji
// TODO: could probably be inferred from the Params
ParamsRaw extends RouteParamsRawGeneric = RouteParamsRawGeneric,
Params extends RouteParamsGeneric = RouteParamsGeneric,
Meta extends RouteMeta = RouteMeta,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this type param because it was never used and I figured it's safer to add it back later if needed than leaving an unused type param that can eventually be used. I marked this as a fix because the leftover type param should have never been released in the first place

Anoesj reacted with thumbs up emoji
@posva posva merged commit 0ce408d into vuejs:main Apr 25, 2025
5 of 8 checks passed
negezor pushed a commit to negezor/vue-router that referenced this pull request Jul 4, 2025
Co-authored-by: Eduardo San Martin Morote <posva13@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@posva posva posva approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /