首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在页面刷新或单击链接后,vue路由器最后一个路由不会呈现

在页面刷新或单击链接后,vue路由器最后一个路由不会呈现
EN

Stack Overflow用户
提问于 2021-07-06 16:06:46
回答 1查看 37关注 0票数 0

当我单击菜单链接时,我的最后一个vue路由器组件正常加载,但当我共享链接或刷新页面时,组件不会呈现。我不知道什么可能是问题,因为它只发生在最后一条路线上。这里有一个链接:https://www.hvarboating.com/speed-boat-hire-hvar-flyer747

我的路由器:

代码语言:javascript
复制
import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

export const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import(/* webpackChunkName: "about" */ '../views/Home')

  },
  {
    path: '/blue-caves-croatia',
    name: 'GroupToursDetails',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/GroupToursDetails')
  },
  {
    path: '/boat-tours',
    name: 'BoatTours',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/BoatTours')
  },

  {
    path: '/hvar-boat-rental',
    name: 'BoatRentals',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/BoatRentals')
  },
  {
    path: '/from-split-to-Hvar-transfer',
    name: 'BoatTransfers',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/BoatTransfers')
  },

  {
    path: '/hvar-weather',
    name: 'Weather',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Weather')
  },
  {
    path: '/frequently-asked-questions',
    name: 'Faq',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Faq')
  },
  {
    path: '/contact',
    name: 'Contact',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Contact')
  },
  {
    path: '/:id',
    meta: {
      sitemap: {
        slugs: [
          'blue-cave-tour-from-hvar',
          'best-beaches-in-hvar-private',
          'zlatni-rat-brac-island',
          'boat-party-tour'

        ]
      }
    },
    name: 'details',
    props:true,
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/PrivateToursDetails')
  },
  {
    path: '/:id',
    meta: {
      sitemap: {
        slugs: [
          'speed-boat-hire-hvar-flyer747',
          'luxury-boat-hire-hvar-tornado38',


        ]
      }
    },
    name: 'rentals',
    props:true,
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/BoatRentDetails')
  },
]

const router = new VueRouter({
  scrollBehavior() {
    return {x: 0, y: 0}
  },
  mode: 'history',
  base: process.env.BASE_URL,
  routes,

})

export default router
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-06 19:03:48

您的最后两个路由具有相同的路径/:id,因此如果您通过路由名称切换路由,它可以正常工作,但是当您刷新或使用链接时,它不知道您要使用哪条路由,因此无法呈现组件。

解决方案:对每条路由使用唯一路径

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68266791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档