123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import Router from 'uni-router-interceptor'
- const router = new Router({
- homePage: '/pages/home/index'
- })
- // 路由白名单
- const whiteList = [
- '/pages/login/index',
- '/pages/login/self',
- '/pages/login/sms',
- '/pages/login/setPwd',
- '/pages/login/register',
- '/pages/login/choose',
- '/pages_law/service',
- '/pages_law/privacy'
- ]
- router.beforeEach((to, from, next) => {
- console.log('router before', to, from)
-
- if (to.url.startsWith('/pages/login/index')) {
- const appid = uni.getStorageSync('appid') || null
- if (
- appid &&
- from &&
- !from.startsWith('pages/login/self')) {
- router.reLaunch('/pages/login/self')
- } else {
- next()
- }
- return
- }
-
- if (whiteList.includes(to.url) || (to.query && to.query.check == 0)) {
- next()
- return
- }
- const token = uni.getStorageSync('token') || null
- if (!token) {
- router.reLaunch('/pages/login/index')
- } else {
- next()
- }
- })
- router.afterEach((to, from) => {
- // console.log('router afterEach', to, from)
- })
- router.error(() => {
- if (process.env.NODE_ENV !== 'development') {
- router.reLaunch('/pages/home/index')
- }
- })
- export default router
|