-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Endpoint] add react router to endpoint app #53808
Changes from 5 commits
dad6c7e
3a43db7
e76c7e0
9561018
1349fd0
7317dd0
eff2be6
1d5221e
3044cf2
83ca184
899b9cf
88aeb48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,24 +8,57 @@ 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, createHashHistory } from 'history'; | ||
import { Route, Router, 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, { element }: AppMountParameters) { | ||
coreStart.http.get('/api/endpoint/hello-world'); | ||
|
||
ReactDOM.render(<AppRoot />, element); | ||
const history = createHashHistory(); | ||
ReactDOM.render(<AppRoot history={history} />, element); | ||
|
||
return () => { | ||
ReactDOM.unmountComponentAtNode(element); | ||
}; | ||
} | ||
|
||
const AppRoot = React.memo(() => ( | ||
interface RouterProps { | ||
history: History; | ||
} | ||
|
||
const AppRoot: React.FC<RouterProps> = React.memo(({ history }) => ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI - just noticed in the TS typing definition that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch, fixed 👍 |
||
<I18nProvider> | ||
<h1 data-test-subj="welcomeTitle"> | ||
<FormattedMessage id="xpack.endpoint.welcomeTitle" defaultMessage="Hello World" /> | ||
</h1> | ||
<Router history={history}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using React Router's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could also probably write a helper function to just navigate us to a real url. Other plugins in Kibana all seem to use hashes and I just wanna understand why. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the "old" platform client side framework was hash based so that might be the reason why all (most) current functional test use it. 🤷♂ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that we figured out support for "real" URLs, consider using react-router's |
||
<Switch> | ||
<Route | ||
exact | ||
path="/" | ||
render={() => ( | ||
<h1 data-test-subj="welcomeTitle"> | ||
<FormattedMessage id="xpack.endpoint.welcomeTitle" defaultMessage="Hello World" /> | ||
</h1> | ||
)} | ||
/> | ||
<Route | ||
path="/management" | ||
render={() => ( | ||
<h1 data-test-subj="endpointManagement"> | ||
<FormattedMessage | ||
id="xpack.endpoint.endpointManagement" | ||
defaultMessage="Manage Endpoints" | ||
/> | ||
</h1> | ||
)} | ||
/> | ||
<Route | ||
render={() => ( | ||
<FormattedMessage id="xpack.endpoint.notFound" defaultMessage="Page Not Found" /> | ||
)} | ||
/> | ||
</Switch> | ||
</Router> | ||
</I18nProvider> | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment further below - this might not be needed if we use React-router's
HashRouter
component