Vue 2/VueRouter:在子路线上无法刷新页面
Vue 2/VueRouter : can't refresh page when on children routes
我无法弄清楚当我在子路线上导航时发生了什么(在上面的示例中 http://<mydomain>/applis
),然后刷新页面 => 我有一个
Not Found // The requested URL /applis was not found on this server
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
可能是我没理解子路由的基本概念?
在您的案例中似乎有问题的是 parent 路由 /
而您已经有 /login
路由。这也是 /
的 child。正如 documentation 所说:
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.
您可以查看示例 here 以了解如何使用嵌套路由。 link:
中的示例代码
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 }
]
}
]
})
如果您可以用您的更改创建 fiddle,这将有助于提供准确的修复。
我无法弄清楚当我在子路线上导航时发生了什么(在上面的示例中 http://<mydomain>/applis
),然后刷新页面 => 我有一个
Not Found // The requested URL /applis was not found on this server
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
可能是我没理解子路由的基本概念?
在您的案例中似乎有问题的是 parent 路由 /
而您已经有 /login
路由。这也是 /
的 child。正如 documentation 所说:
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.
您可以查看示例 here 以了解如何使用嵌套路由。 link:
中的示例代码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 }
]
}
]
})
如果您可以用您的更改创建 fiddle,这将有助于提供准确的修复。