| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import {
- RouterMount,
- createRouter,
- runtimeQuit
- } from 'uni-simple-router';
- //配置白名单
- let WHiTE_LIST=['login']
- let first = null;
- const router = createRouter({
- platform: process.env.VUE_APP_PLATFORM,
- APP:{
- animation:{
- animationType:'slide-in-top',
- animationDuration:300
- }
- },
- routerBeforeEach:(to, from, next) => {
- if (WHiTE_LIST.includes(to.name)) {
- next();
- }else{
- //拦截未登录页面并跳转到登录页面
- let phone =uni.getStorageSync("phone")
- console.log(phone);
- if (phone) {
- next();
- }else{
- next({
- name: 'login',
- params: { fullPath: to.fullPath },
- NAVTYPE: 'replaceAll'
- });
- }
- }
- },
- routerAfterEach:(to, from) => {
- console.log('--------routerAfterEach----')
- },
- routerErrorEach:({type,msg})=>{
- console.log({type,msg})
- // #ifdef APP-PLUS
- if(type===3){
- router.$lockStatus=false;
- runtimeQuit();
- }
- // #endif
- },
- routes: [
- ...ROUTES,
- {
- path: '*',
- redirect:(to)=>{
- return {name:'404'}
- }
- },
- ]
- });
- let count=0;
- router.beforeEach((to, from, next) => {
- // if(count==0){
- // next({
- // path:'/pages/login/login',
- // NAVTYPE:'replaceAll'
- // })
- // }else{
- // next();
- // }
- next();
- count++;
- });
- router.afterEach((to, from, next) => {
- console.log('afterEach---跳转结束')
- });
- export {
- router,
- RouterMount
- }
|