天天看点

React项目引入路由(基础)

1. 安装工具包

npm install react-router-dom      

2. 引入路由器、路由、Switch等

import {BrowserRouter,Route,Switch} from 'react-router-dom'
import Admin from './pages/admin';
import Login from './pages/login';
export default class App extends Component {

    render() {
        return (
            <BrowserRouter>
                <Switch>
                    <Route path='/login' component={Login}></Route>
                    <Route path='/' component={Admin}></Route>
                </Switch>
            </BrowserRouter>
        )
    }
}