react-router
Posted zhanglanzuopin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了react-router相关的知识,希望对你有一定的参考价值。
import {Provider} from ‘react-redux‘ import {Router, hashHistory, Route, IndexRoute, Switch} from ‘react-router‘; import store from ‘redux/store.js‘; // redux store import KYRYComponent from ‘./components/KYRYComponent‘; const routes = ( {/* redux 所有组件共用 */} <Provider store={store}> <Router history={hashHistory}> <Route path="/" component={App}> {/*3个角色 */} <IndexRoute component={KYRYComponent} /> <Route path="cloudProfile" component={CloudOverviewView}/> <Route path="*" component={Error}/></Route> </Router> </Provider> ); ReactDOM.render(routes, document.getElementById(‘root‘));
import React from ‘react‘; // import Experimentlist from ‘../StudentComponent/Experimentlist‘; // import Classmangement from ‘../TeacherComponent/Classmangement‘; // import CloudOverviewView from ‘../page/CloudOverviewView‘; // import Myclass from ‘../StudentComponent/Personalcenter/Myclass‘; import DataCenterOverviewView from ‘../page/DataCenterOverviewView‘; class KYRYComponent extends React.PureComponent { constructor(props){ super(props); } render(){ //如果student 走这个组件 user_type怎么来的 // if(user_type==‘Student‘) { // return <Myclass /> //如果Teacher 走这个组件 // }else if(user_type==‘Teacher‘){ // return <Classmangement /> //如果Admin 走这个组件 首页走这个 // }else{ return <DataCenterOverviewView /> // } } } export default KYRYComponent;
以上是关于react-router的主要内容,如果未能解决你的问题,请参考以下文章
使用 webpack 和 react-router 进行延迟加载和代码拆分不加载