4545 * @module Initialization
4646 */
4747
48- import { createBrowserHistory } from 'history' ;
48+ import { createBrowserHistory , createMemoryHistory } from 'history' ;
4949import {
5050 publish ,
5151} from './pubSub' ;
@@ -59,14 +59,16 @@ import { configure as configureI18n } from './i18n';
5959import { APP_PUBSUB_INITIALIZED , APP_CONFIG_INITIALIZED , APP_AUTH_INITIALIZED , APP_I18N_INITIALIZED , APP_LOGGING_INITIALIZED , APP_ANALYTICS_INITIALIZED , APP_READY , APP_INIT_ERROR } from './constants' ;
6060
6161/**
62- * A browser history object created by the [history](https://github.com/ReactTraining/history)
62+ * A browser history or memory history object created by the [history](https://github.com/ReactTraining/history)
6363 * package. Applications are encouraged to use this history object, rather than creating their own,
64- * as behavior may be undefined when managing history via multiple mechanisms/instances.
65- *
64+ * as behavior may be undefined when managing history via multiple mechanisms/instances. Note that
65+ * in environments where browser history may be inaccessible due to `window` being undefined, this
66+ * falls back to memory history.
6667 */
67- export const history = createBrowserHistory ( {
68- basename : getConfig ( ) . PUBLIC_PATH ,
69- } ) ;
68+ export const history = ( typeof window !== 'undefined' ) ?
69+ createBrowserHistory ( {
70+ basename : getConfig ( ) . PUBLIC_PATH ,
71+ } ) : createMemoryHistory ( ) ;
7072
7173/**
7274 * The default handler for the initialization lifecycle's `initError` phase. Logs the error to the
@@ -126,7 +128,7 @@ export async function analytics() {
126128}
127129
128130function applyOverrideHandlers ( overrides ) {
129- const noOp = async ( ) => { } ;
131+ const noOp = async ( ) => { } ;
130132 return {
131133 pubSub : noOp ,
132134 config : noOp ,
0 commit comments