docs: fix relative redirect example #2479
Merged
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.

The current example in the
Relative redirectingsection of the docs seems misleading:Returning the value
'profile'won't necessarily yield a path of/users/123/profile. A relative path is resolved relative the current active route, not thetoroute.When this was first pointed out to me I thought it was a bug, but based on #1902 it seems it's considered correct. The reproduction provided in #1902 is almost identical to the example in the docs - I'm not sure whether posva was aware of that when he closed that issue.
Perhaps this is something that should be changed in the next major version? I'm not sure how the current behaviour would be useful in practice, having the redirect resolve relative to the
toroute seems much more useful.This example in the docs comes from #1090, which updated an earlier example. From reading through that PR I'm not entirely clear what the original intent was.
I think we have 3 options here to fix the docs (short of a major rewrite):
Relative redirectingsection. Using a function forredirectis already covered further up, so we wouldn't be losing much.redirect. I'm reluctant to go with this option because (as I noted above) this feels like an undesirable feature to me and it's easier to change it if it isn't explicitly documented.This PR implements option 2, but I'm happy to switch to one of the other options if they seem preferable.
For testing purposes, I've put together a playground based on this example: