我使用的是嵌套路由,因此可能会导致此问题,但是,我不确定如何解决此问题。我有以下路线和子路线:
{
path: '/summoner/:summonerName',
component: Summoner,
children: [
{ path: '', component: Matchlist },
{ path: '/match/:matchId', component: SpecificMatch, name: 'specificMatch' }
]
},
当我在路径/summoner/:summonerName
上时,我想查看默认的Summoner父组件和Matchlist
组件;当我在路径/summoner/:summonerName/match/:matchId
上时,我想查看默认的Summoner父级和specificMatch
子级组件。但是,当我尝试使用时,效果很好:
this.$router.push({ name: 'specificMatch', params: { summonerName: this.summoner, matchId: matchId, summonerInfo: this.summonerInfo, match: match}})
我被发送到/match/:matchId
路径而不是/summoner/:summonerName/match/:matchId
,它破坏了组件,因为组件需要从路径中获取用户名。我以为this.$router.push
会把我带到正确的路径,a。任何提示如何解决此问题?
答案 0 :(得分:1)
您的名称为'specificMatch'
的路线具有指定的绝对路径'/match/:matchId'
,因此可以在这里导航。如果您希望将路径追加到父路径的路径,则必须使路径相对,这意味着省去了初始斜杠(/
)-e.i. path: 'match/:matchId'
。