我正在使用Vue应用程序,并且想为默认路由设置精确的路径匹配。我在React和Angular上都有经验,并且都给了选项exact
和pathMatch:'full'
,所以默认路由只有在完全匹配的情况下才会生效。
实际上,当我刷新我的应用程序时,默认路由会被触发并将用户带回到第一页。有没有办法在Vue中做类似的事情?
routes: [
{
path: "/",
name: "home",
component: Home
// how can I add exact match config here?
},
{
path: "/login",
name: "login",
component: () =>
import(/* webpackChunkName: "about" */ "./views/Login.vue")
},
{
path: "/charts",
name: "charts",
component: () =>
import(/* webpackChunkName: "about" */ "./views/ChartDemo.vue")
}
]
答案 0 :(得分:1)
请尝试按此顺序排列您的路线,因为Vue-router的路线顺序很重要。匹配从顶部开始:
routes: [
{
path: "/login",
name: "login",
component: () =>
import(/* webpackChunkName: "about" */ "./views/Login.vue")
},
{
path: "/charts",
name: "charts",
component: () =>
import(/* webpackChunkName: "about" */ "./views/ChartDemo.vue")
},
{
path: "/",
name: "home",
component: Home
// how can I add exact match config here?
}
]