Commit 92334c13 authored by 周远喜's avatar 周远喜

多语言和登陆限制功能添加

parent af2e874e
......@@ -15,6 +15,7 @@ import menuSider from '@/menu/sider';
import { frameInRoutes } from '@/router/routes';
export default {
middleware: 'auth',
components: { MainLayout },
created() {
// const filterMenuSider = getMenuSider(menuSider, "home");
......
import util from '@/libs/util';
export default function ({ route, req, res, redirect, store }) {
var token = util.cookies.get('token');
if (!token) {
redirect("/account/login");
}
}
\ No newline at end of file
export default function ({ isHMR, app, store, route, params, error, redirect }) {
const defaultLocale = app.i18n.fallbackLocale
// If middleware is called from hot module replacement, ignore it
if (isHMR) { return }
// Get locale from params
const locale = params.lang || defaultLocale
if (!store.state.locales.includes(locale)) {
return error({ message: 'This page could not be found.', statusCode: 404 })
}
// Set locale
store.commit('SET_LANG', locale)
app.i18n.locale = store.state.locale
// If route is /<defaultLocale>/... -> redirect to /...
if (locale === defaultLocale && route.fullPath.indexOf('/' + defaultLocale) === 0) {
const toReplace = '^/' + defaultLocale + (route.fullPath.indexOf('/' + defaultLocale + '/') === 0 ? '/' : '')
const re = new RegExp(toReplace)
return redirect(
route.fullPath.replace(re, '/')
)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment