redux路由配置
程序员文章站
2022-03-07 21:29:37
路由基本配置npm ireact-router-domimport React from 'react'import {HashRouter,Route,Switch,Link} from 'react-router-dom'import Index from '../pages/component/Index.js'import Register from '../pages/component/info/register.js'import Setting from '../page....
路由基本配置
npm i react-router-dom
import React from 'react'
import {HashRouter,Route,Switch,Link} from 'react-router-dom'
import Index from '../pages/component/Index.js'
import Register from '../pages/component/info/register.js'
import Setting from '../pages/component/info/setting.js'
import childerenSetting from '../pages/component/info/childerenSetting.js'
const BasicRoute=()=>(
<HashRouter>
<Link to='/index'>回到首页</Link>
<Link to='/register'>Register</Link>
<Link to='/setting'>setting</Link>
<Switch>
<Route exact path='/' component={Index}></Route>
<Route exact path='/index' component={Index}></Route>
<Route exact path='/register' component={Register}></Route>
<Route exact path='/setting' render={()=>
<Setting>
<Route exact path="/setting" component={Setting} />
<Route path="/setting/childerenSetting" component={childerenSetting} />
</Setting>
} ></Route>
</Switch>
</HashRouter>
)
export default BasicRoute
npm i react-router-config react-loadable配置路由
import {renderRoutes} from 'react-router-config'
function App() {
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<div className="App">
附近的开始啦JFK了
<HashRouter>
{renderRoutes(routes)}
</HashRouter>
</div>
</PersistGate>
</Provider>
);
}
import Loadable from './load.js'
const Index =Loadable( ()=>import('../pages/component/Index.js'))
const Register =Loadable( ()=>import('../pages/component/info/register.js'))
const Setting =Loadable( ()=>import( '../pages/component/info/setting.js'))
const childerenSetting =Loadable( ()=>import( '../pages/component/info/childerenSetting.js'))
const routes=[{
path:'/',
exact:true,
component:Index,
},{
path:'/index',
component:Index,
},{
path:'/register',
component:Register,
},{
path:'/setting',
component:Setting,
}
]
export default routes
本文地址:https://blog.csdn.net/qq_27449993/article/details/107530546
上一篇: 前端学习(九)流式布局
下一篇: (一)EasyFlow使用教程,怎么集成