Skip to content
Snippets Groups Projects
Commit 73307536 authored by m431m's avatar m431m :speech_balloon:
Browse files

Merge branch 'redmine-issues/15312' into 'develop'

REDMINE_ISSUE-15312

See merge request onegeo-suite/sites/onegeo-suite-site-login-vuejs!29
parents 31a7650b ae46588b
No related branches found
No related tags found
No related merge requests found
Pipeline #11809 passed with warnings
...@@ -27,7 +27,10 @@ export default { ...@@ -27,7 +27,10 @@ export default {
watch: { watch: {
'$i18n.locale': function(newValue, oldValue) { '$i18n.locale': function(newValue, oldValue) {
if (newValue !== oldValue) { if (newValue !== oldValue) {
const to = this.$router.resolve({ params: { locale: newValue } }) const to = this.$router.resolve({
params: { locale: newValue },
query: this.$route.query
});
this.$router.push(to.location); this.$router.push(to.location);
} }
} }
......
...@@ -4,6 +4,16 @@ import i18n from '@/i18n'; ...@@ -4,6 +4,16 @@ import i18n from '@/i18n';
Vue.use(VueRouter); Vue.use(VueRouter);
function normalizePathname(pathname) {
const normalizedPath = decodeURI(pathname)
// Replaces repeated slashes in the URL.
.replace(/\/+/g, "/")
// Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize
// Note: Missing native IE support, may want to skip this step.
.normalize()
return `${normalizedPath}/`;
};
const routes = [ const routes = [
{ {
path: '/:locale', path: '/:locale',
...@@ -11,21 +21,33 @@ const routes = [ ...@@ -11,21 +21,33 @@ const routes = [
beforeEnter: (to, from, next) => { beforeEnter: (to, from, next) => {
const locale = to.params.locale; const locale = to.params.locale;
const supported_locales = process.env.VUE_APP_I18N_SUPPORTED_LOCALE.split(','); const supported_locales = process.env.VUE_APP_I18N_SUPPORTED_LOCALE.split(',');
if (locale && !supported_locales.includes(locale) && locale.length !== 2) {
return next(`fr/${locale}`); if (!locale || (locale && !supported_locales.includes(locale) && locale.length !== 2)) {
} return next({
if (!supported_locales.includes(locale)) { path: `${process.env.VUE_APP_I18N_DEFAULT_LOCALE}${to.path.endsWith('/') ? to.path : normalizePathname(to.path)}`,
return next('fr'); query: to.query
});
} }
if (i18n.locale !== locale) {
i18n.locale = locale; if (!to.path.endsWith('/')) {
return next({
path: normalizePathname(to.path),
query: to.query
});
} }
i18n.locale = locale;
return next(); return next();
}, },
children: [ children: [
{ {
path: '', path: '',
redirect: { name: 'SignIn' }, // redirect: { name: 'SignIn' }, ==> IT DOES NOT WORK!
beforeEnter: (to, from, next) => {
return next(`${to.path}signin/`);
}
}, },
{ {
path: 'signin', path: 'signin',
...@@ -91,9 +113,7 @@ const routes = [ ...@@ -91,9 +113,7 @@ const routes = [
}, },
{ {
path: '*', path: '*',
redirect() { redirect: `${process.env.VUE_APP_I18N_DEFAULT_LOCALE}`,
return process.env.VUE_APP_I18N_DEFAULT_LOCALE;
}
} }
]; ];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment