在页面重新加载时将非URL道具传递到路由器链接组件

时间:2019-11-02 02:28:52

标签: vue.js vue-component vue-router

对此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

0 个答案:

没有答案