import React from 'react'
import { Router, Route, IndexRoute } from 'react-router'
import hashHistory from './history'
import App from './base'
//路由懒加载
const table = (location, cb) => {
require.ensure([], (require) => {
cb(null, require('./pages/menu/table').default)
}, 'table')
}
//路由拦截
function isLogin(nextState, replaceState) {
const token = sessionStorage.getItem('token')
if (!token) {
replaceState('/login')
// hashHistory.push('/login')
}
}
export default () => (
<Router history={hashHistory}>
<Route path="/" component={App} onEnter={isLogin}>
<IndexRoute component={Welcome} />
<Redirect exact from="/order" to="/order/index"/><--路由匹配 exact exact是Route下的一条属性,一般而言,react路由会匹配所有匹配到的路由组价,exact能够使得路由的匹配更严格一些。exact的值为bool型,为true是表示严格匹配,为false时为正常匹配。-->
<Route path="/table" getComponent={table} />
<Route path="/echarts" getComponent={echarts} />
<Route path="/editor" getComponent={editor} />
<Route path="/chat" getComponent={chat} />
</Route>
<Route path="/login" getComponent={Login} />
<Route path="/register" getComponent={Register} />
</Router>
react 路由懒加载 和 拦截
最新推荐文章于 2024-08-29 08:30:00 发布