Vue 路由器在重新加载时重定向到主页

aji*_*mar 5 vue.js vue-router vuex

我有一个 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
   },
  ]
}
Run Code Online (Sandbox Code Playgroud)

如何刷新当前页面而不是重定向到主页。

小智 1

好吧,假设您process.env.BASE_URL存在并且正确,那么该home组件就是您的入口点。从您About作为 的子级放置的路线列表中home,可能您的意思是在外面。

无论如何,尝试使所有这些都成为非子级,一旦您确定它们都按预期工作,请再次尝试嵌套子级方法,但请注意文档:

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.
Run Code Online (Sandbox Code Playgroud)

参考: https: //router.vuejs.org/guide/essentials/nested-routes.html