Files
xyflow/example/src/index.js
2020-05-04 16:51:17 +02:00

72 lines
1.6 KiB
JavaScript

import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route, Switch, NavLink, withRouter } from 'react-router-dom';
import Rich from './Rich';
import Basic from './Basic';
import CustomNode from './CustomNode';
import Stress from './Stress';
import Inactive from './Inactive';
import Empty from './Empty';
import './index.css';
const routes = [{
path: '/',
component: Rich,
label: 'Rich'
}, {
path: '/basic',
component: Basic,
label: 'Basic'
},{
path: '/custom-node',
component: CustomNode,
label: 'CustomNode'
}, {
path: '/stress',
component: Stress,
label: 'Stress'
}, {
path: '/empty',
component: Empty
},{
path: '/inactive',
component: Inactive
}];
const navLinks = routes.filter(route => route.label);
const SourceDisplay = withRouter(({ location }) => {
const route = routes.find(route => route.path === location.pathname);
const sourceLink = `https://github.com/wbkd/react-flow/tree/master/example/src/${route.label}/index.js`;
return (
<a className="sourcedisplay" href={sourceLink}>
{'<Source />'}
</a>
);
});
ReactDOM.render((
<Router forceRefresh={true}>
<header>
<a href="https://github.com/wbkd/react-flow">React Flow</a>
<nav>
{navLinks.map(route => (
<NavLink to={route.path} key={route.label} exact>
{route.label}
</NavLink>
))}
</nav>
</header>
<SourceDisplay />
<Switch>
{routes.map(route => (
<Route exact path={route.path} render={() => <route.component />} key={route.path} />
))}
</Switch>
</Router>
), document.getElementById('root'));