【问题标题】:Vue router redirecting to home page on reloadVue路由器在重新加载时重定向到主页
【发布时间】:2020-02-15 09:12:45
【问题描述】:

我有一个包含许多路线的 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
   },
  ]
}

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

【问题讨论】:

    标签: vue.js vuex vue-router


    【解决方案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.
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-16
      • 2020-11-24
      • 2018-07-04
      • 1970-01-01
      • 2019-08-26
      • 1970-01-01
      • 2019-02-01
      • 1970-01-01
      相关资源
      最近更新 更多