-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Implement dynamic redirect (#624) #634
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
Conversation
// 1. resolve relative redirect | ||
const rawPath = resolveRecordPath(redirect, record) | ||
const rawPath = resolveRecordPath(typeof redirect === 'function' ? redirect() : redirect, record) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we cache type of redirect === 'function'
?
I didn't because I thought it was too trivial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't have an impact on performance so I think it's ok this way.
However, I think it's better to call redirect if it's a function and let the rest of the code the same:
redirect = typeof redirect === 'function' ? redirect() : redirect
This way the return of redirect can also be an object with a name and it's more flexible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! You're right, fixing it now
Shouldn't the redirect function have access to the target route to be actually useful? |
@@ -52,7 +52,8 @@ export function createMatcher (routes: Array<RouteConfig>): Matcher { | |||
location: Location | |||
): Route { | |||
const { query, hash, params } = location | |||
const { redirect } = record | |||
const { redirect: originalRedirect } = record | |||
const redirect = typeof originalRedirect === 'function' ? originalRedirect() : originalRedirect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yyx990803 Sure it would be useful, but the target route is match()
-ed after consuming the redirect option... and this
context is not available here, so I don't know what can be passed to the redirect function...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can pass createRoute(record, location)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that makes sense! On it now.
Ideally also need a test case for the |
Right.. I'll get back to it after dinner 😄 |
Strange that I can't seem to run e2e tests on the current PC I'm using (was running fine on another one), Using CI for debug now.. sigh |
Note: |
Apart from tests failing LGTM |
Merging as-is and fixing it later |
With e2e tests