mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-27 16:38:50 +02:00
Merge pull request #655 from Hongarc/patch-1
[feat] update url if user change locale
This commit is contained in:
commit
56738fbd09
1 changed files with 8 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
var AppConstants = require('../constants/AppConstants');
|
||||
var AppDispatcher = require('../dispatcher/AppDispatcher');
|
||||
var util = require('../util');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
|
||||
var ActionTypes = AppConstants.ActionTypes;
|
||||
|
@ -84,6 +85,7 @@ AppConstants.StoreSubscribePrototype,
|
|||
dispatchToken: AppDispatcher.register(function(payload) {
|
||||
var action = payload.action;
|
||||
var shouldInform = false;
|
||||
var oldLocale = _locale;
|
||||
|
||||
switch (action.type) {
|
||||
case ActionTypes.CHANGE_LOCALE:
|
||||
|
@ -99,6 +101,12 @@ AppConstants.StoreSubscribePrototype,
|
|||
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) {
|
||||
LocaleStore.emit(AppConstants.CHANGE_EVENT);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue