2👍
✅
If you set a default value in redirect
part. It will go to /tutorial/0
, next it will redirect to /tutorial/0
again and again…
If you want to set a default param value. You can implement it in the Tutorial
component.
For example:
// In Tutorial component
beforeRouteEnter() {
this.$route.params.page = this.$route.params.page ? this.$route.params.page : 0
}
1👍
because "/tutorial/0"
matches "/tutorial/:page?"
too.
Since the router configs is First In First out,
you can define your routes like this
{
component: Tutorial,
name: 'tutorial',
path: '/tutorial/0'
},
{
path: '/tutorial/:page?',
redirect: '/tutorial/0'
}
if the current route matches /tutorial/0
, it will render your component. If it doesn’t match /tutorial/0
, Vue will check if it matches /tutorial/:page?
and do the redirection if it matches.
Source:stackexchange.com