Vue 2/VueRouter:在子路由上无法刷新页面

H.Q*_*tre 5 routes vue.js vuejs2

我无法弄清楚在子路线上导航时发生了什么(在上面的示例中http://<mydomain>/applis),然后刷新页面 => 我有一个

Not Found // 在此服务器上找不到请求的 URL /applis

import MyComponentView from './components/MyComponent.vue'
import LoginView from './components/Login.vue'
import NotFoundView from './components/404.vue'
import DashboardView from './components/subcomp1/Dashboard.vue'
import ApplisView from './components/subcomp1/Applis.vue'

const routes = [
  {
    path: '/login',
    component: LoginView
  }, {
    path: '/',
    component: MyComponentView,
    children: [
      {
        path: '',
        component: DashboardView,
        name: 'Dashboard',
        description: 'Overview of environment'
      }, {
        path: '/applis',
        component: ApplisView,
        name: 'Applis',
        description: 'Applications list'
      }
    ]
  }, {
    path: '/*',
    component: NotFoundView
  }
]
export default routes
Run Code Online (Sandbox Code Playgroud)

可能我还没有理解子路线的基本概念?

Sau*_*abh 1

在您的情况下,似乎错误的是当/您已经有一条路线时却有一条父/login路线。这也是 的子项/。正如文档所说:

以 / 开头的嵌套路径将被视为根路径。这允许您利用组件嵌套而无需使用嵌套 URL。

您可以查看此处的示例,了解如何使用嵌套路由。来自此链接的示例代码:

const router = new VueRouter({
  routes: [
    { path: '/user/:id', component: User,
      children: [
        // UserHome will be rendered inside User's <router-view>
        // when /user/:id is matched
        { path: '', component: UserHome },

        // UserProfile will be rendered inside User's <router-view>
        // when /user/:id/profile is matched
        { path: 'profile', component: UserProfile },

        // UserPosts will be rendered inside User's <router-view>
        // when /user/:id/posts is matched
        { path: 'posts', component: UserPosts }
      ]
    }
  ]
})
Run Code Online (Sandbox Code Playgroud)

如果您可以根据更改创建一个小提琴,这将有助于提供准确的修复。