我有一个有很多路线的 vue 应用程序。每当我尝试重新加载页面时,它总是将我重定向到主页而不是刷新当前页面。
下面是我的路由器设置:
export default new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: '/',
name: 'home',
component: Home,
children: [
{
path: "/dashboard",
name: 'dashboard',
component: DashboardView
},
{
path: "/About",
name:'about',
component: About
},
{
path: "/comments",
name:'comments',
component: Comments
},
]
}
如何刷新当前页面而不是重定向到主页。
最佳答案
好吧,假设您的 process.env.BASE_URL
存在且正确,home
组件是您的切入点。
从您的路线列表中,您放置了 About
作为 home
的 child ,可能你的意思是在外面。
无论如何,尝试使所有这些都成为非子级,一旦您确定它们都按预期工作,请再次尝试嵌套子级方法,但请注意文档:
Note that nested paths that start with / will be treated as a root path. This allows you to leverage the component nesting without having to use a nested URL.
引用:
https://router.vuejs.org/guide/essentials/nested-routes.html
关于vue.js - 重新加载时Vue路由器重定向到主页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58449717/