打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
vue-router在嵌套router中router-view失效的一个惊天大坑

近日遇到一个奇怪的问题,现象是在<router-link>点击链接时,如果没有加上target="_blank",在一个新页面打开时,在一个nest router中的<router-view>中不会显示,重新刷新页面就显示出来了。

代码如下:

Index.vue

 <q-item-label lines="2" class="col-auto gt-sm YL__list_line_height YL__list_font_size">
            <span v-if="item.emphsis != 'null'" class="text-weight-bold">{{ item.emphsis }}</span
            >{{ item.detailBrief }}
            <router-link
              :to="{
                path: 'item',
                name: 'detail',
                params: { id: item.id },
              }"
              >...阅读全文
            </router-link>
          </q-item-label>

DetailLayout.vue

<template>
  <q-layout view="hHh lpR fFf" class="bg-secondary">
    <q-page-container class="bg-primary">
      <router-view />
    </q-page-container>

    <q-drawer
      side="right"
      :width="300"
      :breakpoint="700"
      show-if-above
      content-class="bg-primary text-white"
    >
    </q-drawer>
  </q-layout>
</template>

<script>
export default {
  name: 'DetailLayout',
};
</script>

routers.js

import DetailPage from 'pages/DetailPage.vue';

const routes = [
  {
    path: '/',
    component: () => import('layouts/MainLayout.vue'),
    children: [
      {
        path: '',
        component: () => import('layouts/IndexLayout.vue'),
        children: [
          {
            path: '',
            component: () => import('layouts/IndexTabLayout.vue'),
            children: [
              { path: '', component: () => import('pages/Index.vue') },
              { path: 'rank', component: () => import('pages/Index.vue') },
              { path: 'cheap', component: () => import('pages/Index.vue') },
              {
                path: 'search',
                name: 'search',
                component: () => import('pages/Index.vue'),
                props: (route) => ({ query: route.query.q }),
              },
            ],
          },
        ],
      },

      {
        path: '/item/:id',
name: 'detail', component: () => import('layouts/DetailLayout.vue'), // props: true, beforeEnter: (to, from, next) => { console.info('##before enter DetailLayout, to=' + to.fullPath); next(); }, children: [ { path: '', component: () => import('pages/DetailPage.vue'), props: true, beforeEnter: (to, from, next) => { console.info('%%before enter DetailPage, to=' + to.fullPath); next(); }, }, ], // 在router之间传递参数用下面配置 // props: (route) => ({ title: route.query.title, detail: route.query.detail }), }, ], }, { path: '*', component: () => import('pages/Error404.vue'), }, ]; export default routes;

 

 

 
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Vue实现路由跳转和嵌套
成功vue自定义布局
Vue路由传递参数详细说明
Vue 中后台鉴权的另一种思路 - 动态路由的实现与优化
VUE移动端音乐APP学习【二】:页面骨架开发
2年vue项目实战经验汇总(干货)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服