<router-link> not working with named route and hash
See original GitHub issueVersion
3.1.2
Reproduction link
https://codesandbox.io/s/vue-routing-example-bcy1y
Steps to reproduce
switch between pages and check the hash and the url
What is expected?
:to="{name: 'hello', hash: 'test'}" => /hello#test
What is actually happening?
:to="{name: 'hello', hash: 'test'}" => /hellotest
Hash is working fine when using path so it’s definitely not a major or blocking problem but I personally use named route whenever I can and also with nuxt-i18n and the hash is just appended without the # to the route.
Thanks for the awesome work.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Angular2 Routing with Hashtag to page anchor - Stack Overflow
This appends the hash to the end of my url properly, but it doesn't anchor to the div with the same name. I'm...
Read more >Different History modes - Vue Router
The history option when creating the router instance allows us to choose among different history modes. Hash Mode #. The hash history mode...
Read more >How to Use Vue Router: A Complete Tutorial - Vue School Blog
On line 3 we are declaring an array of objects named routes. This array represents our routes in the application.
Read more ><Link> · React Router
A <Link> can know when the route it links to is active and automatically apply an ... and will not scroll to the...
Read more >Common Routing Tasks - Angular
The following command uses the Angular CLI to generate a basic Angular application with an application routing module, called AppRoutingModule , which is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Same problem here, please reopen this issue.
<router-link :to="{ name: 'home', hash: '#contact-us' }">Contact Us</router-link> The link becomes /home#contact-us When clicked, the URL changes, but the pages doesn’t scroll.
Although I got not even an error in the console.
I found a workaround to this behaviour - if you insert this (found on the router documentation) in your router configuration
then scrolling works as expected after page navigation. Still I think this should be a default behaviour.
<router-link :to="{ name: 'home', hash: '#contact-us' }">Contact Us</router-link>
The link becomes/home#contact-us
When clicked, the URL changes, but the pages doesn’t scroll. Also there is an error in the console:Uncaught Error: Syntax error, unrecognized expression: /home#contact-us