mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-28 05:58:38 +02:00
feat: prototype building dynamic react route
This commit is contained in:
parent
e8e1d5e097
commit
b1e785b6c3
6 changed files with 103 additions and 8 deletions
|
@ -1,10 +1,34 @@
|
|||
import React from 'react';
|
||||
import {render} from 'react-dom';
|
||||
import theme from '@theme';
|
||||
import {BrowserRouter, Route, Switch} from 'react-router-dom';
|
||||
import Hello from '@theme/hello';
|
||||
import Layout from '@theme/layout';
|
||||
|
||||
class App extends React.Component {
|
||||
render() {
|
||||
return <div>Hello world! {theme()} </div>;
|
||||
// https://reacttraining.com/react-router/web/example/route-config
|
||||
const routes = [
|
||||
{
|
||||
path: '/',
|
||||
component: Hello
|
||||
},
|
||||
{
|
||||
path: '/layout',
|
||||
component: Layout
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<div>
|
||||
<Switch>
|
||||
{routes.map(({path, component}) => (
|
||||
<Route key={path} exact path={path} component={component} />
|
||||
))}
|
||||
</Switch>
|
||||
</div>
|
||||
</BrowserRouter>
|
||||
);
|
||||
}
|
||||
}
|
||||
render(<App />, document.getElementById('app'));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue