vue.js - 重新加载时Vue路由器重定向到主页

标签 vue.js vuex vue-router

我有一个有很多路线的 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/

相关文章:

vue.js - Vue JS 路由器查询传递并绑定(bind)到 axios

ajax - Nuxtjs Axios 在 Vuex 模块 CORS 错误

vue.js - 映射的 Vuex 函数 "is not a function",但仍然加载

vue.js - 按键删除对象不会更新vue组件

javascript - Firebase存储,将图像检索到vue应用

vue.js - 未捕获( promise )类型错误 : Cannot read property 'catch' of undefined

vue.js - Vue DOM 对计算属性没有反应

vue.js - 导入组件时 VueJS 模块未发现错误

javascript - 将重复的查询参数推送到 Vue 路由器

javascript - 错误 : Cannot find module 'vue-loader-v16/package.json'