gpt4 book ai didi

routes - Vue 2/Vue 路由器 : can't refresh page when on children routes

转载 作者:搜寻专家 更新时间:2023-10-30 22:51:59 27 4
gpt4 key购买 nike

我无法弄清楚当我在子路线上导航时发生了什么(在上面的示例中 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

可能是我不了解子路由的基本概念?

最佳答案

在您的情况下,似乎有一个父路由 / 而您已经有一个 /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了解如何拥有嵌套路线。此链接中的示例代码:

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 ,这将有助于提供准确的修复。

关于routes - Vue 2/Vue 路由器 : can't refresh page when on children routes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41504715/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com