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.
What is breaking
Users no longer can use unencoded static paths:
{ path: '/cassé' }
<router-link to="/cassé" />
<router-link :to="{ path '/cassé' }" />
router.push('/cassé')
router.push({ path: '/cassé' })
They have to manually encode them with
encodeURI()
or use a named route:This is only necessary with string locations. When using params and query, the behavior is still the same and using named routes with params is recommended for that reason:
In fact, this PR makes this possible, it wasn't working before.
Similarly, doing
router.push({ name: 'servers', params: { server: 'one/two' }})
will change the url to/servers/one%2Ftwo
while giving the correct value in$route.params.server
.Why this can't be done automatically by the router
We could automatically call
encodeURI()
on each static segment of a path but this would also break code for users who are already correctly encodingpath
(you should always encode URLs, even before this change).How to help the migration
Since we were never supposed to pass an unencoded
path
to a route record or even callrouter.push()
with an unencoded string orpath
property, I propose to warn in dev mode if any unencoded character is passed to help people be aware of how they should encode their routes.Internal explanation
Previously, this used to work because we were decoding paths twice, but this created other problems like errors with URLs containing the character
%
encoded. By fixing this bug we must remove thedecode
call made on the path when matching against existing routes, but this also makes it impossible to automatically encodepath
anymore because the user wouldn't be able to provide encoded characters, e.g. the/
character (%2F
) would be transformed to its encoded version,%252F
(%
is encoded as%25
) and there wouldn't be a way to match an encoded slash character which is necessary in segments of the URL since the slash character is used to differentiate segments in a URL. Without this change, we can't correctly decode%2F
Overall, this makes things consistent and it's also the same behavior that exists in v4
Close #3337
Close #3103
Close #3125