Vue路由配置-嵌套路由

目录结构

在这里插入图片描述

film.vue

<template>
	<div>
		<ul>
			<li>加载show组件</li>
			<li>加载comingsoon组件</li>
		</ul>
		<!--路由容器-->
		<router-view></router-view>
	</div>
</template>

<script>
</script>

<style>
	ul {
		display: flex;
	}

	li {
		flex-grow: 1;
	}
</style>

index.js

import Vue from "vue";
// 从vue-router里面导入VueRouter
import VueRouter from "vue-router";
//导入相关组件
import film from "@/views/film.vue"
import center from "@/views/center.vue"
import cinema from "@/views/cinema.vue"
import show from "@/views/film/show.vue"
import comingsoon from "@/views/film/comingsoon.vue"
//注册模块
Vue.use(VueRouter);

const routes = [{
		//路径
		path: "/film",
		//组件
		component: film,
		//嵌套路由
		children: [{
				path: "show",
				component: show
			},
			{
				path: "comingsoon",
				component: comingsoon
			},
		]
	},

	{
		path: "/center",
		component: center
	},
	{
		path: "/cinema",
		component: cinema
	},
	{
		path: "*", //通配符
		redirect: "/film" //重定向
	}
]

const router = new VueRouter({
	routes: routes
})

export default router

效果展示,http://localhost:8080/#/film/show会在film下展示其子组件show

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值