vue.js - Vue-router 在运行时改变模式
问题描述
我使用选项实例化 vue-router:
mode: "abstract"
之后,我想在运行时更改路线:
this.$router.mode = 'hash';
然后我导航:
this.$router.push({name: 'test'});
URL 中没有散列。
那么如何在运行时更改模式呢?
解决方案
更改模式不会做任何事情,而模式仅在 VueRouter 的构造函数中使用。在 VueRouter 模式下,执行以下代码(https://github.com/vuejs/vue-router/blob/dev/src/index.js):
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}`)
}
}
但基本上最好重新创建你的 VueRouter
推荐阅读
- php - 当我在 php 中连接两个数组时要生成多少个新数组
- c# - 我想使用 C# 在我的函数应用程序 azure 中调用 rest api
- android - 断言失败:第 205 行 POS 16:IMAGEURL != NULL 不正确
- asp.net - Hangfire 仪表板“无法刷新统计信息:服务器响应 500(内部服务器错误)。尝试手动重新加载页面..”
- oracle - 如何使用 terraform 在 easydns 中自动添加 dns 条目?
- xml - XSLT 输出位于需要 ns1:response 的标题父级下
- android - getLayoutManager() 在 RecyclerView 适配器中返回 null
- jquery - Asp.Net Core 5.0 MVC Web app Ajax post 抛出错误
- mysql - 如何使用带有汉字的名称转储表格?
- python - 我想使用外键更新不同模型中的布尔字段