Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.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 为什么$router.push({name:';召唤者';,参数:{courderName:courderName}})会导致url/courger/username/而不是/courger/username?_Javascript_Vue.js_Vuejs2_Vue Router - Fatal编程技术网

Javascript 为什么$router.push({name:';召唤者';,参数:{courderName:courderName}})会导致url/courger/username/而不是/courger/username?

Javascript 为什么$router.push({name:';召唤者';,参数:{courderName:courderName}})会导致url/courger/username/而不是/courger/username?,javascript,vue.js,vuejs2,vue-router,Javascript,Vue.js,Vuejs2,Vue Router,我试图执行一个函数,当用户单击某个元素时,它会将用户重定向到另一个页面 this.$router.push({ name: 'matchlist', params: { summonerName: summonerName }}) 导致URL/caller/username/而不是/caller/username。如果您没有注意到,在第一个URL的末尾有一个反勾号,如果我在/caller/username 如果我使用这个: this.$router.push({ path: `/summone

我试图执行一个函数,当用户单击某个元素时,它会将用户重定向到另一个页面

this.$router.push({ name: 'matchlist', params: { summonerName: summonerName }})
导致URL
/caller/username/
而不是
/caller/username
。如果您没有注意到,在第一个URL的末尾有一个反勾号,如果我在
/caller/username

如果我使用这个:

this.$router.push({ path: `/summoner/${summonerName}` })
我被发送到
/caller/username
,一切正常,但我仍然很好奇为什么在第一个示例中会出现这种情况

路线:

{
    path: '/summoner/:summonerName',
    component: Summoner,
    children: [
        { path: '', component: Matchlist, name: 'matchlist' },
        { path: 'match/:matchId', component: SpecificMatch, name: 'specificMatch' }
    ]
}
功能:

    redirectToProfile(participant){
        let summonerName = participant.identity.player.summonerName
        this.$router.push({ name: 'matchlist', params: { summonerName }})
        //this.$router.push({ path: `/summoner/${summonerName}` })
    },

下面是关于github上的问题的讨论

解决方案是在路由中添加
pathToRegexpOptions:{strict:true}


Josh Deltener的一把小提琴展示了一个例子:

这有关系吗?遗憾的是,应该包含答案的JSFIDLE不会为我打开。是的,JSFIDLE现在不高兴:/“Backtick”?你是说正斜杠吗?一个反勾号(也称为grave)是
`
您在对
push()
的调用中获得了
{name:'caller'}
,但您的路线没有该(或任何)名称