uni-simple-router
uni-simple-router copied to clipboard
路由守卫进首页时不被触发
问题描述 配置的router.beforeEach,进入首页时不会触发,后续的跳转可以触发
复现步骤 [复现问题的步骤]
const routeHooks = {
'/pages/transfer/index': {
beforeEnter: (to, from, next) => {
console.log('1111111111111111sssssssssss')
next()
}
}
}
const router = createRouter({
platform: process.env.UNI_PLATFORM,
routes: ROUTES.map(route => {
if (routeHooks[route.path]) {
return Object.assign({}, route, routeHooks[route.path])
}
return route
})
});
//全局路由前置守卫
router.beforeEach((to, from, next) => {
console.log('wwww')
next();
});
/pages/transfer/index 这个就是首页,初始进入/pages/transfer/index时,beforeEach没有被触发,后续跳转到其他页面时都可以触发,因为想做进页面前判断是否已经登录,所以需要在进入首页的时候就能够触发beforeEach
预期结果 希望项目被打开,进入第一个页面的时候也能触发beforeEach
实际结果 打开第一个页面时,beforeEach没有被触发,后续的页面跳转是能够触发的
// pages.json
"pages": [ // pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
{
"path": "pages/transfer/index",
"name": "transfer",
"style": {
"navigationBarTitleText": "首页",
"navigationStyle": "custom"
}
}
],
"subPackages": [
{
"root": "pagesA",
"pages": [
{
"path": "list/list",
"name": "pagesAList",
"style": {}
}
]
}
],
// main.js
import Vue from 'vue'
import App from './App'
import {router} from './router.js';
Vue.use(router)
App.mpType = 'app'
const app = new Vue({
...App,
store
})
app.$mount()
Hello, have you solved your problem?
文档中说明了h5的使用方式
已解决了该问题,解决方式跟yeao提供的方式一样,感谢支持