mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-09 22:55:35 +00:00
Fix standalone router bugs
This commit is contained in:
@@ -56,7 +56,7 @@ export default class Coriolis extends React.Component {
|
|||||||
this.state = {
|
this.state = {
|
||||||
page: null,
|
page: null,
|
||||||
language: getLanguage(Persist.getLangCode()),
|
language: getLanguage(Persist.getLangCode()),
|
||||||
route: null,
|
route: {},
|
||||||
sizeRatio: Persist.getSizeRatio()
|
sizeRatio: Persist.getSizeRatio()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
import Persist from './stores/Persist';
|
import Persist from './stores/Persist';
|
||||||
|
|
||||||
|
let standalone = undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the app is running in mobile/tablet 'standalone' mode
|
* Determine if the app is running in mobile/tablet 'standalone' mode
|
||||||
* @return {Boolean} True if the app is in standalone mode
|
* @return {Boolean} True if the app is in standalone mode
|
||||||
*/
|
*/
|
||||||
function isStandAlone() {
|
function isStandAlone() {
|
||||||
try {
|
if (standalone === undefined) {
|
||||||
return window.navigator.standalone || (window.external && window.external.msIsSiteMode && window.external.msIsSiteMode());
|
try {
|
||||||
} catch (ex) {
|
standalone = window.navigator.standalone || (window.external && window.external.msIsSiteMode && window.external.msIsSiteMode());
|
||||||
return false;
|
} catch (ex) {
|
||||||
|
standalone = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return standalone;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,14 +49,14 @@ Router.start = function() {
|
|||||||
if (isStandAlone()) {
|
if (isStandAlone()) {
|
||||||
let state = Persist.getState();
|
let state = Persist.getState();
|
||||||
// If a previous state has been stored, load that state
|
// If a previous state has been stored, load that state
|
||||||
if (state && state.name && state.params) {
|
if (state && state.path) {
|
||||||
Router(this.props.initialPath || '/');
|
Router.replace(state.path, null, true);
|
||||||
} else {
|
} else {
|
||||||
Router('/');
|
Router.replace('/', null, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let url = location.pathname + location.search;
|
let url = location.pathname + location.search;
|
||||||
Router.replace(url, null, true, true);
|
Router.replace(url, null, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -68,6 +73,9 @@ Router.go = function(path, state) {
|
|||||||
let ctx = new Context(path, state);
|
let ctx = new Context(path, state);
|
||||||
Router.dispatch(ctx);
|
Router.dispatch(ctx);
|
||||||
if (!ctx.unhandled) {
|
if (!ctx.unhandled) {
|
||||||
|
if (isStandAlone()) {
|
||||||
|
Persist.setState(ctx);
|
||||||
|
}
|
||||||
history.pushState(ctx.state, ctx.title, ctx.canonicalPath);
|
history.pushState(ctx.state, ctx.title, ctx.canonicalPath);
|
||||||
}
|
}
|
||||||
return ctx;
|
return ctx;
|
||||||
@@ -85,7 +93,12 @@ Router.go = function(path, state) {
|
|||||||
Router.replace = function(path, state, dispatch) {
|
Router.replace = function(path, state, dispatch) {
|
||||||
gaTrack(path);
|
gaTrack(path);
|
||||||
let ctx = new Context(path, state);
|
let ctx = new Context(path, state);
|
||||||
if (dispatch) Router.dispatch(ctx);
|
if (dispatch) {
|
||||||
|
Router.dispatch(ctx);
|
||||||
|
}
|
||||||
|
if (isStandAlone()) {
|
||||||
|
Persist.setState(ctx);
|
||||||
|
}
|
||||||
history.replaceState(ctx.state, ctx.title, ctx.canonicalPath);
|
history.replaceState(ctx.state, ctx.title, ctx.canonicalPath);
|
||||||
return ctx;
|
return ctx;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user