二级路由书写不显示初始页面

当我们需要用到二级路由时,会先想到去看文档。文档看不懂怎么办?还是看看别人的文章。

创建二级路由

  1. 首先创建二级路由页面,有几个创建几个。

  2. 其次需要在router里面配置二级路由

router 复制代码
{
        path:'/sort',
        name:'sort',
        component:()=>import('../views/Sort.vue'),
        //子路由
        children:[
            {
                path:'photoGraphy',
                component:()=>import( '../components/Content/PhotoGraphy.vue')
            },
            {
                path:'switc',
                component:()=>import('../components/Content/Switc.vue'),
            },
            {
                path:'light',
                component:()=>import('../components/Content/Light.vue'),
            }
        ]
    },
  1. 在父页面里面放置: 标签router-link 和 router-view

  2. 在router-link里面写上:

js 复制代码
:to="/sort/PhotoGraphy"

//使用了v-for可以这么写,这也是你拼接其他属性的用法
:to="'/sort/'+ item.id " 

//编程式的导航,不需要router-link标签
this.$router.push('/parent/child');

初始页面点击才渲染

这时候就需要

  1. 路由重定向(推荐)
perl 复制代码
redirect: '/sort/PhotoGraphy', // 当访问 /sort 时自动重定向到 /sort/PhotoGraphy
  1. 默认子路由

给子路由:path: '', // 空路径作为默认子路由。

但是不推荐,我使用发现他确实会立即渲染,但是点回去页面就失效。

相关推荐
志尊宝1 小时前
Vue3 零基础每日笔记(080):Vue3 + ECharts 数据可视化——封装可复用图表组件
前端·javascript·vue.js·笔记·信息可视化·echarts
阿狗童鞋1 小时前
前端工程化实战指南
前端
CappuccinoRose1 小时前
CSS 动效基础
前端·css·动画·animation·transition
用户4402818278071 小时前
我用 TRAE 一晚上从零撸了个微信投票小程序: 17 个云函数 + 11 个页面的全链路实战
前端
BullSmall1 小时前
SonarQube 9.9.8-community 适配 Jenkins 版本说明
java·前端·jenkins
tryCbest1 小时前
第一篇:HTML5 核心知识全解 + 项目起步
前端·html·html5
百度一下吧1 小时前
CSS 伪类使用与实践:从入门到进阶
前端·css
hunterandroid1 小时前
android方案 : Multiplatform 跨平台开发实战:一套代码,多端运行
android·前端
百度一下吧1 小时前
CSS3 之后新增的特性:从 CSS4 到现代 CSS 的演进
前端·css·css3