Introduction react-route4

cmd

npm i react-route react-router react-router-dom --save

import

import { HashRouter,Route, Switch } from 'react-router-dom';

render

let routeArr = [
            {route:'/ni',component:Container},
        ]
        return (
            <HashRouter>  
                <Switch>
                    <Route exact path='/' component={Container}/>
                    {
                        routeArr.map(v=><Route key={v.route} path={v.route} component={v.component}/>)
                    }
                    {/* <Redirect to="/ni" /> */}
                </Switch>
            </HashRouter>
        )

tips

 If you do not know or want to be friends of the students can micro-channel contact me: qq981145483 (Note: csdn fe)

Published 57 original articles · won praise 5 · views 20000 +

Guess you like

Origin blog.csdn.net/qq_33807889/article/details/99724608