Closed JudahGabriel closed 1 year ago
We could accept a callback in addition to a string for the redirect
plugin, and then pass the context
to the callback, e.g.:
redirect((context) => `/foo/${context.params.name}`);
and then change the implementation to something like:
export function redirect(path) {
return {
name: 'redirect',
shouldNavigate: (context) => ({
condition: () => false,
redirect: typeof path === 'function' ? path(context) : path
})
}
}
Would you be willing to create a PR for that? :)
Cool. Sure thing, I'll submit a PR.
Thanks for merging! Closing this issue.
I want this to work, but it doesn't:
If a user navigates to /legacy/foo/bar, I want it to redirect to /foo/bar.
Unfortunately it navigates to the literal URL
/foo/:name
What's the best way to make this work? My thought is to create a plugin that finds the path params and inserts the real values for them. But that seems tedious because I'd have to write code to be aware of different kinds of path params, like
:name
,:name?
,:name+
,:name(foo|bar)
, etc.Is there a better way?