I have two path with same component like this:
/:loc("-host")
- should match /usa-host
/:loc/:sublocation("-host")
- should match /usa/washington-host
how to achieve this using single named route in vue.js
I have two path with same component like this:
/:loc("-host")
- should match /usa-host
/:loc/:sublocation("-host")
- should match /usa/washington-host
how to achieve this using single named route in vue.js
You can use alias of path
Check in doc
Also check fiddle : https://jsfiddle.net/nikleshraut/9sgk6yg4/1/
Note : Opening same component is not working by default, you need to use other trick. For just testing above fiddle, go
home
->/projects
andhome
->/project/1
will work but/projects
->/project/1
or/project/1
->/projects
will not work. To make it work do something like this : https://jsfiddle.net/nikleshraut/9sgk6yg4/This is my solution.
Router:
Use
?
to separate param from literal in route.Component:
Set local variables from $route.params.
Template:
Use
:key="$route.fullPath"
to ensure component re-creates each navigation.Fiddle here