我正在使用 404 错误页面功能,我可以使用它:
const router = new VueRouter({
routes: [
// ...
{
path: '*',
component: NotFound,
name: '404',
meta: {page_title: 'Vuejs&Material Demo | 404 NOT FOUND'}
},
]
});
// ... not found something
this.$router.push({name: '404'});
上面的问题是url也改变了,但我只想改变 View (组件)。
当一个简单的拼写错误重定向到 http://example.com/404 时,我觉得非常烦人,它让我再次输入网址或从浏览器自动填充中转到,无论哪种方式我都不喜欢。
我想知道是否有某种方法/逻辑可以有这样的东西:https://www.facebook.com/sdfsd/sfsdf/asfasfsafastgtgregre .
底线,我想要改变 View ,但不改变网址。
有没有任何 vue/vue-router 方法可以做到这一点?
最佳答案
这有点 hacky,但您可以通过路由器的 history
对象的 updateRoute
方法更新路由:
let route = this.$router.match({ name: '404' });
this.$router.history.updateRoute(route);
关于javascript - 更改 View /组件但不更改 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47101126/