javascript 反应路由器
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 反应路由器相关的知识,希望对你有一定的参考价值。
//https://reacttraining.com/react-router/web/example/route-config
import React from "react"
import { BrowserRouter as Router, Route, Link } from "react-router-dom"
// first our route components
const Main = () => <h2>Main</h2>
const Sandwiches = () => <h2>Sandwiches</h2>
const Tacos = ({ routes }) => (
<div>
<h2>Tacos</h2>
<ul>
<li>
<Link to="/tacos/bus">Bus</Link>
</li>
<li>
<Link to="/tacos/cart">Cart</Link>
</li>
</ul>
{routes.map((route, i) => (
<RouteWithSubRoutes key={i} {...route} />
))}
</div>
)
const Bus = () => <h3>Bus</h3>
const Cart = () => <h3>Cart</h3>
const routes = [
{
path: "/sandwiches",
component: Sandwiches
},
{
path: "/tacos",
component: Tacos,
routes: [
{
path: "/tacos/bus",
component: Bus
},
{
path: "/tacos/cart",
component: Cart
}
]
}
]
const RouteWithSubRoutes = route => (
<Route
path={route.path}
render={props => (
<route.component {...props} routes={route.routes} />
)}
/>
)
const RouteConfigExample = () => (
<Router>
<div>
<ul>
<li>
<Link to="/tacos">Tacos</Link>
</li>
<li>
<Link to="/sandwiches">Sandwiches</Link>
</li>
</ul>
{routes.map((route, i) => (
<RouteWithSubRoutes key={i} {...route} />
))}
</div>
</Router>
)
export default RouteConfigExample
以上是关于javascript 反应路由器的主要内容,如果未能解决你的问题,请参考以下文章
javascript 反应路由器
javascript 反应路由器:应用程序模板
javascript 异步反应路由器组件加载
javascript 反应路由器
javascript 反应路由器Dom
javascript 反应路由器滚动到顶部