Skip to content
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

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Anoesj
Copy link

@Anoesj Anoesj commented Mar 13, 2025

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

Deploy Preview for vue-router ready!

Name Link
🔨 Latest commit 92f0d4d
🔍 Latest deploy log https://app.netlify.com/sites/vue-router/deploys/67d2b9f1f1a78f0008dbe068
😎 Deploy Preview https://deploy-preview-2475--vue-router.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 97 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant