| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- // router.js
- import { RouterMount, createRouter, runtimeQuit } from '@/js_sdk/hhyang-uni-simple-router/uni-simple-router';
- import tools from "@/service/tools";
- const router = createRouter({
- platform: process.env.VUE_APP_PLATFORM,
- routerErrorEach:({type,level,...args})=>{
- // console.log({type,level,...args})
- // #ifdef APP-PLUS
- if(type===3){
- router.$lockStatus=false;
- tools.onBackPress()
- }
- // #endif
- },
- routes: [...ROUTES]
- });
- //全局路由前置守卫
- const whiteList = ['/pages/text/index','/pages/login/forget','/pages/login/register','/pages-user/pages/explain','/pages/index/down']
- router.beforeEach((to, from, next) => {
- const userToken = uni.getStorageSync('token')
- // const userMid = uni.getStorageSync('m_id')
- console.log('userToken:'+userToken)
- // console.log('m_id:'+userMid)
- console.log('path:'+to.fullPath)
- // #ifdef APP-PLUS
- if(!userToken && whiteList.indexOf(to.path)<0){
- if(to.fullPath!=='/pages/login/index'){
- next('/pages/login/index');
- }
- }else if(userToken && to.fullPath==='/pages/login/index'){
- next('/pages/index/index');
- }
- // #endif
- // #ifdef H5
- if(process.uniEnv.version==='prod'){
- let wapUrl=['/pages/login/register','/pages-user/pages/explain','/pages/index/down']
- if(wapUrl.indexOf(to.path)<0){
- next('/pages/index/down');
- }
- }
- // #endif
- next();
- });
- // 全局路由后置守卫
- router.afterEach((to, from) => {
- // console.log('后置守卫to------', to)
- })
- export {
- router,
- RouterMount
- }
|