feat(router): Allow redirect routes to use route names as target #10376
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When specifying a redirect route like
<Route path="/simple" redirect="/newSimple" name="simple" />
the value ofredirect
is the path of the page the user should be redirected to. However, the paths can be long and annoying to type out. And if they ever change the redirect would now be broken.Also, for private routes we do this:
Here, if a user isn't authenticated, the user will be redirected to the
home
route. Notice how the target route is specified by its name (home
) instead of its path (/
).With this PR it's now also possible to redirect using the name of the target route, making our route behavior more consistent. So this will now work
Old style paths still works. The logic is super simple -> if the
redirect
value starts with/
it's assumed to be a path. If not, it's assumed to be a route name. This should make this PR fully backwards compatible.