Reputation: 3802
I want to create a router navigation and prevent 404 errors. When manipulating a valid URL to an invalid one the next router link won't work anymore. I created a working example
https://codesandbox.io/s/8l60y06pmj
To see the problem do the following steps:
Click on the link navigating to page 2
change the url https://8l60y06pmj.codesandbox.io/#/pageTwo
to https://8l60y06pmj.codesandbox.io/#/pageTwo/whateverYouLike
Click on the link navigating to page 3
Now you should have the following URL
https://8l60y06pmj.codesandbox.io/#/pageTwo/pageThree
but the correct URL should be
https://8l60y06pmj.codesandbox.io/#/pageThree
You can reset this behaviour by clicking on the link navigating to the home view.
How can I fix this?
Upvotes: 0
Views: 254
Reputation: 191
Inside of NavbarComponent.vue
, you need to add a /
to both of the page links; it should look something like this after the changes.
<router-link to="/pageTwo">Page Two</router-link> |
<router-link to="/pageThree">Page Three</router-link>
Without that slash, you aren't actually telling Vue Router to send the user to a new page.
Here's a working version of your CodeSandbox.
Upvotes: 1