Vue.js Vue路由器在运行时更改模式
我使用以下选项实例化vue路由器:Vue.js Vue路由器在运行时更改模式,vue.js,vue-router,Vue.js,Vue Router,我使用以下选项实例化vue路由器: mode: "abstract" 之后,我想在运行时更改路由: this.$router.mode = 'hash'; 然后我导航: this.$router.push({name: 'test'}); URL中没有散列 那么如何在运行时更改模式呢?那么,为什么不使用模式启动它:“hash”?更改模式没有任何作用,而该模式仅在VueRouter的构造函数中使用。在VueRouter模式下,执行以下代码(): 但基本上,最好重新创建VueRouter,因为
mode: "abstract"
之后,我想在运行时更改路由:
this.$router.mode = 'hash';
然后我导航:
this.$router.push({name: 'test'});
URL中没有散列
那么如何在运行时更改模式呢?那么,为什么不使用
模式启动它:“hash”
?更改模式没有任何作用,而该模式仅在VueRouter的构造函数中使用。在VueRouter模式下,执行以下代码():
但基本上,最好重新创建VueRouter,因为应用程序的行为应该是这样的。因此,我需要动态地更改模式。我更喜欢历史记录,但由于浏览器兼容性,必须使用哈希。
switch (mode) {
case 'history':
this.history = new HTML5History(this, options.base)
break
case 'hash':
this.history = new HashHistory(this, options.base, this.fallback)
break
case 'abstract':
this.history = new AbstractHistory(this, options.base)
break
default:
if (process.env.NODE_ENV !== 'production') {
assert(false, `invalid mode: ${mode}`)
}
}