mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-27 16:38:50 +02:00
feat: update url if user change locale
This commit is contained in:
parent
079689c51a
commit
e00b5b640b
1 changed files with 8 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
var AppConstants = require('../constants/AppConstants');
|
var AppConstants = require('../constants/AppConstants');
|
||||||
var AppDispatcher = require('../dispatcher/AppDispatcher');
|
var AppDispatcher = require('../dispatcher/AppDispatcher');
|
||||||
|
var util = require('../util');
|
||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
var ActionTypes = AppConstants.ActionTypes;
|
var ActionTypes = AppConstants.ActionTypes;
|
||||||
|
@ -84,6 +85,7 @@ AppConstants.StoreSubscribePrototype,
|
||||||
dispatchToken: AppDispatcher.register(function(payload) {
|
dispatchToken: AppDispatcher.register(function(payload) {
|
||||||
var action = payload.action;
|
var action = payload.action;
|
||||||
var shouldInform = false;
|
var shouldInform = false;
|
||||||
|
var oldLocale = _locale;
|
||||||
|
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ActionTypes.CHANGE_LOCALE:
|
case ActionTypes.CHANGE_LOCALE:
|
||||||
|
@ -99,6 +101,12 @@ AppConstants.StoreSubscribePrototype,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (util.isBrowser() && oldLocale !== _locale) {
|
||||||
|
var url = new URL(document.location.href);
|
||||||
|
url.searchParams.set('locale', _locale);
|
||||||
|
window.history.replaceState({}, '', url.href);
|
||||||
|
}
|
||||||
|
|
||||||
if (shouldInform) {
|
if (shouldInform) {
|
||||||
LocaleStore.emit(AppConstants.CHANGE_EVENT);
|
LocaleStore.emit(AppConstants.CHANGE_EVENT);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue