其他分享
首页 > 其他分享> > Vue路由配置-重定向

Vue路由配置-重定向

作者:互联网

如果用户访问了一个无效的url(ex:http://localhost:8080/#/filmasdasdasdasd),我们要给这个url进行一个默认的跳转

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"
//注册模块
Vue.use(VueRouter);

const routes = [{
		//路径
		path: "/film",
		//组件
		component: film
	},
	{
		path: "/center",
		component: center
	},
	{
		path: "/cinema",
		component: cinema
	},
	{
		//通配符
		path: "*", 
		//重定向
		redirect: "/film" 
	}
]

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

export default router

效果展示,输入无效url后,回车自动跳转至/film

在这里插入图片描述

标签:Vue,重定向,cinema,vue,路由,VueRouter,path,import,film
来源: https://blog.csdn.net/weixin_43321280/article/details/118035183