react-router的使用
项目中react路由的使用
import React, { Component } from 'react'
import { Router, Route, Link } from 'react-router'
//import相应组件
import RentDetail from './routes/RentDetail'
import BuildingDetail from './routes/BuildingDetail'
const BUILD_ID = 181512
const RENT_ID = 221
const App = () => {
return (
<div>
<Link to={`/rent_detail/${RENT_ID}`}>招租</Link>
<Link to={`/building_detail/${BUILD_ID}`}>楼栋</Link>
</div>
)
}
// 路由配置
export default class Root extends Component {
render() {
return (
<Router history={this.props.history}>
<Route path="/" component={App} />
<Route path="/rent_detail/:id" component={RentDetail} />
<Route path="/building_detail/:id" component={BuildingDetail} />
</Router>
)
}
}