Merge pull request #11801 from Bouncey/fix/langRoutes
Fix: Lang routes persist between sessions
This commit is contained in:
@ -16,6 +16,7 @@ import flashToToast from './utils/flash-to-toast';
|
|||||||
|
|
||||||
import createApp from '../common/app';
|
import createApp from '../common/app';
|
||||||
import provideStore from '../common/app/provide-store';
|
import provideStore from '../common/app/provide-store';
|
||||||
|
import { getLangFromPath } from '../common/app/utils/lang';
|
||||||
|
|
||||||
// client specific sagas
|
// client specific sagas
|
||||||
import sagas from './sagas';
|
import sagas from './sagas';
|
||||||
@ -34,6 +35,8 @@ const DOMContainer = document.getElementById('fcc');
|
|||||||
const initialState = isColdStored() ?
|
const initialState = isColdStored() ?
|
||||||
getColdStorage() :
|
getColdStorage() :
|
||||||
window.__fcc__.data;
|
window.__fcc__.data;
|
||||||
|
const primaryLang = getLangFromPath(window.location.pathname);
|
||||||
|
|
||||||
initialState.app.csrfToken = csrfToken;
|
initialState.app.csrfToken = csrfToken;
|
||||||
initialState.toasts = flashToToast(window.__fcc__.flash);
|
initialState.toasts = flashToToast(window.__fcc__.flash);
|
||||||
|
|
||||||
@ -42,7 +45,7 @@ window.__fcc__ = {};
|
|||||||
|
|
||||||
const serviceOptions = { xhrPath: '/services', context: { _csrf: csrfToken } };
|
const serviceOptions = { xhrPath: '/services', context: { _csrf: csrfToken } };
|
||||||
|
|
||||||
const history = useLangRoutes(createHistory)();
|
const history = useLangRoutes(createHistory, primaryLang)();
|
||||||
sendPageAnalytics(history, window.ga);
|
sendPageAnalytics(history, window.ga);
|
||||||
|
|
||||||
const devTools = window.devToolsExtension ? window.devToolsExtension() : f => f;
|
const devTools = window.devToolsExtension ? window.devToolsExtension() : f => f;
|
||||||
|
@ -23,9 +23,9 @@ function getLangFromLocation(location) {
|
|||||||
return getLangFromPath(location.pathname);
|
return getLangFromPath(location.pathname);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function useLangRoutes(createHistory) {
|
export default function useLangRoutes(createHistory, primaryLang) {
|
||||||
return (options = {}) => {
|
return (options = {}) => {
|
||||||
let lang = 'en';
|
let lang = primaryLang || 'en';
|
||||||
const history = createHistory(options);
|
const history = createHistory(options);
|
||||||
const unsubscribeFromHistory = history.listen(nextLocation => {
|
const unsubscribeFromHistory = history.listen(nextLocation => {
|
||||||
lang = getLangFromLocation(nextLocation);
|
lang = getLangFromLocation(nextLocation);
|
||||||
|
Reference in New Issue
Block a user