export default async function ({ store, req, redirect, route, error, app, localePath, }) { const userInfo = store.state.auth.userInfo if (!userInfo) { await store.dispatch('auth/getUserInfo') } const routes = store.getters['permission/leafMenus'] const currentRoute = localePath(route.path, app.i18n.defaultLocale) if (currentRoute === '/') { if (routes && routes.length > 0) { redirect(localePath(routes[0].fullPath)) return true } else { return error({ statusCode: 404 }) } } if ( !routes.find( (mRoute) => mRoute.fullPath !== '/' && currentRoute.startsWith(mRoute.fullPath) ) ) { return error({ statusCode: 404 }) } }