Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何重定向到vue路由器中带有参数的路由器_Javascript_Vue.js_Vue Router - Fatal编程技术网

Javascript 如何重定向到vue路由器中带有参数的路由器

Javascript 如何重定向到vue路由器中带有参数的路由器,javascript,vue.js,vue-router,Javascript,Vue.js,Vue Router,我想这样组织我的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(当前_date可以视为新日期

我想这样组织我的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(当前_date可以视为新日期())

下面是我的vue路由器配置

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]缺少命名路由的参数”结果:应定义“lang”

那么如何将参数lang传递给“结果”路由器呢

模式:“历史”, 路线:[{ 路径:“/”, //重定向:'/en/home', //将默认值设置为lang base url 重定向:()=>{ 返回'/en' } },{ 路径:'/:lang', 姓名:"郎",, //组件:()=>导入(“./Frame.vue”), 组成部分:{ 模板:“”,//如果Frame.vue中没有特殊代码 }, //重定向:{name:'home'}, 重定向:至=>({ 路径:'/'+to.params.lang+'/home',//传递的用户lang:lang }), 儿童:[{ 路径:“家”, 姓名:'家', 组件:()=>导入(“./components/Home.vue”) },{ 路径:“结果/:日期”, 名称:“结果”, 组件:()=>导入(“./components/ResultDay.vue”) },{ 路径:“结果”, 重定向:{name:'result',参数:{date:new date()}}, }] }]
如果您想实现支持i18n的网站,可以尝试以下方法: mode: 'history', routes: [{ path: '/', // redirect: '/en/home', // set default to lang base url redirect: () => { return '/en' } },{ path: '/:lang', name: 'lang', // component: () => import("./Frame.vue"), component: { template: '', // if you have no special codes in Frame.vue }, // redirect: {name: 'home'}, redirect: to => ({ path: '/'+to.params.lang+'/home', // user lang passed by :lang }), 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()}}, }] }]