Commit 0bd6bf4a by 李乾广

增加路由跳转判断

1 parent 88d55b53
import {createRouter, createWebHashHistory} from 'vue-router' import {createRouter, createWebHashHistory} from 'vue-router'
import * as Cookies from 'js-cookie'
const menuRoute = [ const menuRoute = [
{ {
path: '/Main', path: '/Main',
...@@ -90,6 +90,12 @@ const route = [ ...@@ -90,6 +90,12 @@ const route = [
path: '/', path: '/',
redirect: '/Main/SnapshotCluster', redirect: '/Main/SnapshotCluster',
}, },
{
path: '/404',
name: '404',
component: () =>
import ('@/views/error-page/404')
},
{ {
path: '/test', path: '/test',
component: () => import("@/views/Test/Test.vue"), component: () => import("@/views/Test/Test.vue"),
...@@ -103,5 +109,12 @@ const router = createRouter( ...@@ -103,5 +109,12 @@ const router = createRouter(
routes: route routes: route
} }
) )
// 全局路由守卫
router.beforeEach((to, from, next) => {
if ((Cookies.get('userrole_type')&&Cookies.get('userrole_type')==-1)||to.path == '/404') {
next();
} else {
router.push('/404');
}
});
export default router export default router
<template>
<div class="error-container">
<h1>404</h1>
<p>
<strong>File not found</strong>
</p>
<p>The site configured at this address does not contain the requested file.</p>
<p>
<router-link to="/" class="back-link">Back to Home</router-link>
</p>
</div>
</template>
<script>
export default {
}
</script>
<style scoped>
.error-container {
margin: 50px auto 40px auto;
width: 600px;
text-align: center;
}
h1 {
width: 800px;
position: relative;
left: -100px;
letter-spacing: -1px;
line-height: 60px;
font-size: 60px;
font-weight: 100;
margin: 0 0 50px 0;
text-shadow: 0 1px 0 #fff;
}
p {
color: rgba(0, 0, 0, 0.5);
margin: 20px 0;
line-height: 1.6;
}
.back-link {
color: #3BB8FF;
text-decoration: none;
}
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!