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

add "href" property to ResolvedRoute #364

Merged
merged 3 commits into from
Dec 14, 2024

Conversation

stackoverfloweth
Copy link
Contributor

@stackoverfloweth stackoverfloweth commented Dec 14, 2024

this is step 1 of a couple different initiatives.

1.) we need a key that's unique to handle transitions when params change, currently using route.id but that won't change when params change. With this new href property, we will have a better candidate. (this is really just a 1 line docs change, so I decided to commit it here)

2.) we want to avoid "widening" the route inside of RouterLink, currently users might use an explicit route name as part of the ToCallback which uses RouterResolve and returns a Url. Once we "widen" from an explicit route name to a Url, we've found that will sometimes actually point to a different route now, causing a bad DX and confusion.

Copy link

netlify bot commented Dec 14, 2024

Deploy Preview for kitbag-router ready!

Name Link
🔨 Latest commit 324c4e9
🔍 Latest deploy log https://app.netlify.com/sites/kitbag-router/deploys/675dd844358ef90008b6e0eb
😎 Deploy Preview https://deploy-preview-364--kitbag-router.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

docs/advanced-concepts/transitions.md Outdated Show resolved Hide resolved
@@ -39,5 +40,6 @@ export function getResolvedRouteForUrl(routes: Routes, url: string, state?: unkn
params: getRouteParamValues(route, url),
state: getStateValues(route.state, state),
hash,
href: asUrl(url)
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems a little odd we need asUrl. But I get why.


```html{3}
<router-view>
<template #default={ component, route }>
<transition name="fade" :key="route.key">
<transition name="fade" :key="route.href">
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you add href to RouterRoute?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep

id: route.id,
matched: route,
matches: [route],
name: type,
query: createResolvedRouteQuery(''),
params: {},
state: {},
href: '/',
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm hard coding this to '/' is interesting. This is really only used for NotFound when the initialUrl doesn't match anything right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes that's where we use this reject route. The actual href of the rejection route is probably never actually used anywhere but required to satisfy the type

@stackoverfloweth stackoverfloweth merged commit 82acbc1 into main Dec 14, 2024
6 checks passed
@stackoverfloweth stackoverfloweth deleted the add-href-to-resolved-route branch December 14, 2024 19:42
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.

2 participants