我为 Nuxt 定义了一个命名空间中间件,如下所示:
export default function({ store, redirect, app }){
if (!store.state.isAuth) {
return redirect(app.i18n.localePath('/auth'))
}
}
如果用户未通过身份验证,他们将被重定向到身份验证页面,位于/auth
. 但是,这是一个多语言站点,所以我需要生成当前语言环境对应的路径。通常我会使用$i18n.localePath
或在这种情况下使用 Nuxt 的context来执行此操作,app.i18n.localePath()
但是我收到此错误:
app.i18n.localePath is not a function
我不知道为什么,因为有一个上下文,并console.log(app.i18n)
告诉我 app.i18n.localePath是一个函数:
...
localePath: [Function: bound ],
...
有什么建议么?谢谢!