我想在一起使用nuxt@auth模块和nuxt-i18n。当我想要有不同的登录页面路径时,问题就会出现。例如:
pages: {
login: {
en: '/authorization',
fr: '/autorisation'
}
}路由运行良好,但是当我尝试使用nuxt@auth并限制所有页面时,默认的重定向请求/login页面。在nuxt.config.js文件中,我可以重写重定向路由,但只能设置一个重定向。
auth: {
redirect: {
login: '/fr/autorisation'
}
}如何向模块显示请求所选语言的路由?提前感谢!
发布于 2020-08-10 13:17:00
希望这对某人有帮助
export default ({ app, $auth }) => {
$auth.onRedirect((to, from) => {
return app.localePath(to)
})
}发布于 2019-01-21 07:31:40
对于这个问题,https://github.com/nuxt-community/auth-module/pull/185似乎有一个解决方案,但在当前版本中,我无法访问onRedirect方法。
我做了个解决办法。我添加了auth-lang-redirect.js插件,它覆盖nuxt.config.js文件中定义的redirect选项。
export default ({ app }) => {
var redirect = app.$auth.$storage.options.redirect
for (var key in redirect) {
redirect[key] = '/' + app.i18n.locale + redirect[key]
}
app.$auth.$storage.options.redirect = redirect
}请注意,我不使用nuxt-i18n模块,但您应该明白这一点。您必须像这样在nuxt.config.js中注册这个插件:
auth: {
strategies: { ... },
redirect: {
login: '/login',
logout: '/',
callback: '/login',
home: '/user/profile'
},
plugins: ['@/plugins/auth-lang-redirect.js']
},发布于 2021-01-02 16:18:41
export default function({ app, $auth }) {
const redirect = { ...$auth.$storage.options.redirect };
const localizeRedirects = () => {
for (const key in redirect) {
$auth.$storage.options.redirect[key] = app.localePath(redirect[key]);
}
};
localizeRedirects();
app.i18n.onLanguageSwitched = () => {
localizeRedirects();
};
}https://stackoverflow.com/questions/52364451
复制相似问题