fix: i18n lint issue

This commit is contained in:
Clark Du 2018-03-01 21:03:36 +08:00
parent 6494873f70
commit 03f89421c2
No known key found for this signature in database
GPG Key ID: D0E5986AF78B86D9

View File

@ -1,5 +1,5 @@
export default function ({ isHMR, app, store, route, params, error, redirect }) { export default function ({ isHMR, app, store, route, params, error, redirect }) {
const defaultLocale = app.i18n.fallbackLocale; const defaultLocale = app.i18n.fallbackLocale
// If middleware is called from hot module replacement, ignore it // If middleware is called from hot module replacement, ignore it
if (isHMR) return if (isHMR) return
// Get locale from params // Get locale from params
@ -11,10 +11,9 @@ export default function ({ isHMR, app, store, route, params, error, redirect })
store.commit('SET_LANG', locale) store.commit('SET_LANG', locale)
app.i18n.locale = store.state.locale app.i18n.locale = store.state.locale
// If route is /<defaultLocale>/... -> redirect to /... // If route is /<defaultLocale>/... -> redirect to /...
if (locale === defaultLocale && route.fullPath.indexOf('/'+defaultLocale) === 0) { if (locale === defaultLocale && route.fullPath.indexOf('/' + defaultLocale) === 0) {
const toReplace = '^/' + defaultLocale
var toReplace = '^/'+defaultLocale const re = new RegExp(toReplace)
var re = new RegExp(toReplace);
return redirect( return redirect(
route.fullPath.replace(re, '/') route.fullPath.replace(re, '/')
) )