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 4D R20详细的安装图文教程


下一篇:Springboot学习笔记(3)——依赖注入之二(Java配置)