Skip to content

Commit

Permalink
use BrowserRouter component
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlog committed Jan 2, 2020
1 parent 3044cf2 commit 83ca184
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions x-pack/plugins/endpoint/public/applications/endpoint/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,28 @@ import * as React from 'react';
import ReactDOM from 'react-dom';
import { CoreStart, AppMountParameters } from 'kibana/public';
import { I18nProvider, FormattedMessage } from '@kbn/i18n/react';
import { History, createBrowserHistory } from 'history';
import { Route, Router, Switch } from 'react-router-dom';
import { Route, BrowserRouter, Switch } from 'react-router-dom';

/**
* This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle.
*/
export function renderApp(coreStart: CoreStart, { appBasePath, element }: AppMountParameters) {
coreStart.http.get('/api/endpoint/hello-world');

const history = createBrowserHistory({ basename: appBasePath });
ReactDOM.render(<AppRoot history={history} />, element);
ReactDOM.render(<AppRoot basename={appBasePath} />, element);

return () => {
ReactDOM.unmountComponentAtNode(element);
};
}

interface RouterProps {
history: History;
basename: string;
}

const AppRoot: React.FunctionComponent<RouterProps> = React.memo(({ history }) => (
const AppRoot: React.FunctionComponent<RouterProps> = React.memo(({basename}) => (
<I18nProvider>
<Router history={history}>
<BrowserRouter basename={basename}>
<Switch>
<Route
exact
Expand Down Expand Up @@ -59,6 +57,6 @@ const AppRoot: React.FunctionComponent<RouterProps> = React.memo(({ history }) =
)}
/>
</Switch>
</Router>
</BrowserRouter>
</I18nProvider>
));

0 comments on commit 83ca184

Please sign in to comment.