vue.js - Vue路由器在哈希模式下错误地处理url
问题描述
我的网站托管在 IIS 上,可以作为machinename/test/
.
当我尝试以machinename/test/
路由方式打开站点machinename/test/#/
时,所有资产都按预期加载。
但是,如果我在machinename/test
路由变为时打开machinename/test#/
,并且资产路径中断。
我该如何解决?我想当去machinename/test
的路径正在成为machinename/test/#/
。
解决方案
这有点hacky,但这应该可行:
在VueRouter
实例化之前,添加:
if (!window.location.pathname.endsWith('test/')) {
window.location.replace(
`${window.location.href}`.replace(
window.location.pathname,
`${window.location.pathname}`.replace(
'/test',
'/test/')
)
)
}
推荐阅读
- python - Django Forms.py 将 EmailField 值更改为自动填充 value="{{ user.email }}"
- reactjs - React 在状态更改后重新渲染子组件
- c - 没有数据发送时如何跳过 recv() 函数
- javascript - 使用 WebUSB 从串行设备读取整个响应
- python-3.x - 如何迭代数据类型为列表的数据框中的列
- azure-devops - Azure DevOps 在部署另一个阶段时取消部署阶段
- javascript - 木偶师一张一张的给元素子截图
- excel - 跳转到一列
- java - 以通用方式从对象中挑选属性
- visual-studio - Visual Studio 2019 不会发布