Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MINOR] shared routing for subapps #1783

Merged
merged 11 commits into from
Jan 14, 2021
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { SubAppDef, SubAppFeatureFactory } from "@xarc/subapp";
import { Router, BrowserRouter } from "react-router-dom";
import { createBrowserHistory } from "history";

import RouterHistory from "./router-history"
import { ReactRouterFeatureOptions, _id, _subId } from "../common";

/**
* Implement the component wrapping support for using react router on a subapp
*/
Expand All @@ -20,10 +18,10 @@ export function reactRouterFeature(options: ReactRouterFeatureOptions): SubAppFe
let history: any;
let TheRouter: any;

if (!options.history) {
if (options.history === false) {
TheRouter = BrowserRouter;
} else {
history = options.history === true ? createBrowserHistory() : options.history;
history = options.history === true ? RouterHistory.history : (options.history instanceof Object ? options.history : RouterHistory.history);
TheRouter = Router;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/xarc-react-router/src/browser/router-history.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createBrowserHistory } from "history";
export default class RouterHistory {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit overkill to create a static value, and no export default

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, this will trigger createBrowserHistory immediately when app's loaded

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

static history = createBrowserHistory();
}