我想按照以下方式组织我的Vue Router:
原始URL | 重定向到 |
---|---|
exmple.com/ |
exmple.com/en/home |
exmple.com/:lang |
exmple.com/:lang/home (:lang 是一个参数,表示语言) |
example.com/:lang/home |
:lang 的主页 |
example.com/:lang/result/:date |
日期的结果页面 |
example.com/:lang/result |
exmaple.com/:lang/result/current_date (current_date 可以被视为 new Date() ) |
下面是我的vue-router配置
const router = new VueRouter({
mode: 'history',
routes: [{
path: '/',
redirect: '/en/home',
},{
path: '/:lang',
name: 'lang',
component: () => import("./Frame.vue"),
redirect: {name: 'home'},
children: [{
path: 'home',
name: 'home',
component: () => import("./components/Home.vue")
},{
path: 'result/:date',
name: 'result',
component: () => import("./components/ResultDay.vue")
},{
path: 'result',
redirect: {name: 'result', params: {date: new Date()}},
}]
}]
});
但是它无法从example.com/en/result
重定向到example.com/en/result/current_date
。JS控制台显示错误为
[vue-router]缺少命名路由“result”的参数:期望定义“lang”
那么我该如何将参数lang
传递给“result”路由器?