1. 程式人生 > >vue-router路由守衛

vue-router路由守衛

路由守衛及獲取cookie裡的GTICKET

ROUTER. beforeEach(( to, from, next) => { var reg = new RegExp( '(^| )' + 'gTicket' + '=([^;]*)(;|$)') var arr = document. cookie. match( reg) const NEXTROUTER = [ 'index'
, 'enter', 'entermessage', 'entermessage2', 'user', 'afterSale', 'saledDetails', 'addSC', 'goodsAdd', 'audit', 'goodsMssage', 'goodsRedact', 'specification'] var GTICKET = '' if ( arr) { GTICKET = unescape
( arr[ 2]) } if ( NEXTROUTER. indexOf( to. name) >= 0) { if ( GTICKET. length === 0) { ROUTER. push({ path: '/'}) } } next() }) export default ROUTER