【发布时间】:2021-06-11 00:20:48
【问题描述】:
我已经为 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 ],
...
有什么建议吗?谢谢!
【问题讨论】: