Skip to content
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

fix(router-link): active class with encoded params #3125

Closed
wants to merge 6 commits into from

Conversation

oleksiikhr
Copy link

@oleksiikhr oleksiikhr commented Feb 15, 2020

I will try to fix this :). Closes #3103

The problem is url generation. We have 2 routes:

<router-link to="/special/tést1">/special/tést1</router-link>
<router-link :to="{ name: 'special', params: {word: 'tést2'} }">/special/tést2</router-link>

In the first case, the route is transmitted as it is. In the second - it is decoded through the library: path-to-regexp (in new versions this can be changed by parameter)

Before:
1

After:
2

But, if it works in History Mode. Then for Hash Mode you need to edit separately, because there the same problem exists.

Somewhere here

Copy link
Member

@posva posva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR but this the fix shouldn't change how URLs are generated. The encoded version should be the one generated. The problem is the other way around: when the page is reloaded, the fullPath property is decoded (/user/tést) instead of being encoded (/user/t%C3%A9st) like it usually is when doing $router.push({ name: 'special', params: { test: 'tést' }})

Regarding the difference between named routes and string-based push like $router.push('/url') and $router.push({ path: '/url' }): when doing string-based push, the user is responsible for encoding the urls but when doing others, the router should encode params for you. That's why the two router-link you added in the e2e test yield different results. But it's expected

You can change things in this pr if you want to or close it and start a new one

@oleksiikhr
Copy link
Author

Thanks for the detailed answer, if not against, I will try to solve it again.

Now encode fullPath strings are compared, and the user now encode his path (changed in tests)

1

@oleksiikhr oleksiikhr changed the title Fix/find init location WIP: Fix/find init location Feb 16, 2020
@oleksiikhr
Copy link
Author

If I understood correctly, then I, as a user, should encode the string in the fallen test.

<li><router-link to="/é">/é</router-link></li>
to
<li><router-link to="/%C3%A9">/é</router-link></li>

@posva
Copy link
Member

posva commented May 26, 2020

@Alexeykhr I updated the original issue at #3103

Going to an unencoded URL is not valid, so it doesn't matter if the active link matches or not, but when visiting the encoded valid url, it should match the link

@oleksiikhr oleksiikhr changed the title WIP: Fix/find init location Fix/find init location May 26, 2020
@posva posva changed the title Fix/find init location fix(router-link): active class with encoded params Aug 3, 2020
@posva posva closed this in #3350 Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Router link active class not applied with non ascii params
2 participants