求助 锤子官网 的 React Router 大概要怎么写?
像
http://锤子/jianguopro/#/overview
http://锤子/m1/#/overview
这样的。
不要跟我讲IDE 生成就好了。最好贴下干货。
求助 锤子官网 的 React Router 大概要怎么写?
Kid
#1
taylorren
#5
我用的是react-router-dom,我是这样写的:
import React from 'react';
import {
BrowserRouter as Router,
Route,
Redirect
} from 'react-router-dom';
import Home from './Home';
import Contact from './Contact';
import BookDetail from './BookDetail';
import BookList from './BookList';
import ReadingList from './ReadingList';
import AuthService from './widget/AuthService';
import Login from './Login';
import Admin from './Admin';
export const auth=new AuthService('...', 'xxxxx.auth0.com');
const requireAuth = auth.loggedIn();
const RoutingConfig = () => (
<Router>
<div>
<Route exact path="/" component={Home}/>
<Route path="/contact" component={Contact}/>
<Route path="/books/:bookid.html" component={BookDetail}/>
<Route path="/books/list/:type?/:key?/:page?" component={BookList}/>
<Route path="/books/readings/:page?" component={ReadingList} />
<Route path="/login" component={Login} auth={auth} />
<Route exact path="/admin" render={() => (
!requireAuth ? (<Redirect to="/login"/> ) : (<Admin/>)
) }/>
</div>
</Router>
);
export default RoutingConfig;