"页面刷新或点击链接后,vue router的最后一个路由不会被渲染"
P粉277824378
P粉277824378 2023-08-26 10:27:45
[Vue.js讨论组]

当我点击菜单链接时,我的最后一个vue-router组件正常加载,但当我分享链接或刷新页面时,组件不会渲染。我不知道可能是什么问题,因为它只发生在最后一个路由上。

这是一个链接:https://www.hvarboating.com/speed-boat-hire-hvar-flyer747

我的路由器:

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
P粉277824378
P粉277824378

全部回复(1)
P粉020085599

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

解决方案:为每个路由使用唯一的路径

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号