this.$router.push 跳转页面后#前面会多一个?
时间: 2023-10-14 08:59:22 浏览: 44
这是因为使用了 vue-router 的 history 模式,通过 this.$router.push 跳转页面时,URL 中的 # 被替换为了 ?,这是为了方便使用浏览器的前进和后退按钮。如果不想要这个 ?,可以使用 hash 模式,或者在使用 history 模式时在路由配置中设置 base 属性。
相关问题
this.$router.push 跳转页面后路径变成?#
在使用 history 模式时,通过 this.$router.push 跳转页面后,URL 中的 # 被替换为了 ?#,这是为了兼容旧版本浏览器的行为。如果你希望 URL 中没有 ?#,可以将路由的 mode 设置为 hash 模式,或者在使用 history 模式时在路由配置中设置 base 属性。另外,可以考虑升级浏览器版本,避免这种问题。
this.$router.push跳转页面后并刷新页面
在 Vue.js 中,`this.$router.push` 方法会进行页面的跳转,但不会刷新页面。如果你希望在页面跳转后刷新页面,可以考虑使用以下方法:
1. 通过给 `this.$router.push` 方法传递一个新的 `key` 参数来实现强制刷新。例如:
```javascript
this.$router.push({
path: '/your-path',
query: { key: Math.random() }
});
```
在目标页面中,可以通过 `this.$route.query.key` 获取到 `key` 的值,并在页面的某个地方使用该值,触发页面重新渲染。
2. 使用 `window.location.reload()` 方法来刷新页面。在跳转完成后,可以手动调用该方法来刷新当前页面。例如:
```javascript
this.$router.push('/your-path').then(() => {
window.location.reload();
});
```
注意,这种方式会刷新整个页面,可能导致数据丢