cloudroam
2024-09-30 e3f789767f9498184782efe4337bda09b5c328f9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 })
  }
}