【发布时间】:2021-06-13 13:34:25
【问题描述】:
我想这样组织我的 vue 路由器:(xxx.com 是我的域)
xxx.com/ -> 重定向到 xxx.com/en/home
xxx.com/:lang -> 重定向到 xxx.com/:lang/home (:lang 是一个参数,意思是语言)
xxx.com/:lang/home -> :lang 的主页
xxx.com/:lang/result/:date -> 日期的结果页
xxx.com/:lang/result -> 重定向到xxx.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()}},
}]
}]
});
但它不能从 xxx.com/en/result 重定向到 xxx.com/en/result/current_date。 JS 控制台显示错误为“[vue-router] missing param for named route "result": Expected "lang" to be defined"
那么如何将参数 lang 传递给“结果”路由器?
【问题讨论】:
-
如果你想实现支持i18n的网站,你可以试试这个:kazupon.github.io/vue-i18n
标签: javascript vue.js vue-router