对此Vue路由器的行为感到困惑。
我正在传递链接URL中未包含的道具。
这里是routes.js
:
{
path: '/matchups/game/:game',
name: 'matchup',
component: Matchup,
props: true
}
这是我的router-view
组件:
<router-link :key="game" :to="{ name: 'matchup', params: {game: game, scoringStats: scoringStats} }">{{ game }}</router-link>
如您所见,scoringStats不包含在URL中,但作为参数传递。
如果我单击链接导航至matchups/game/1
,则子组件将按预期工作。我可以在子组件中访问this.scoringStats
。
但是,如果我在URL matchups/game/1
处重新加载页面,则this.scoringStats
现在是undefined
,并且不会出现在this.$route.params
不确定为什么会这样,或者如何避免。用户为什么要重新加载页面并没有真正的用例,但我想它会发生。
主要是为了开发方便而不必导航回页面。
希望获得帮助!
使用vue-router v3.1.3