学习react 的第八天 (路由重要的知识点)
路由的创建安装和使用(请务必看完)
(此代码包含的知识点 安装 导入 路由 路由的使用 和编程式导航)
import react,{Component} from 'react'
import reactDom from 'react-dom'
import {BrowserRouter as Router,Route,Link} from 'react-router-dom'
class ComponentRouter extends Component{
render(){
return (
<Router>
{}
{}
{}
<div>
<Route path="/a" component={RouterA}></Route>
<Route path="/b" component={RouterB}></Route>
</div>
</Router>
)
}
}
const RouterA=()=>{
return (<span>这是路由A</span>)
}
const RouterB=(props)=>{
const toa=()=>{
props.history.push("/a")
}
return (<span onClick={toa}>这是路由B </span>)
}
export default ComponentRouter
路由的匹配模式 模糊匹配和准确匹配
import react,{Component} from 'react'
import reactDom, { render } from 'react-dom'
import {BrowserRouter as Router,Route,Link} from 'react-router-dom'
class DefualtRouter extends Component{
render(){
return (
<Router>
{}
<Route path='/' component={Home}></Route>
{}
<Route path='/b' component={B}></Route>
{}
<Route exact path="/c" component={c}></Route>
</Router>
)
}
}
const Home=()=>{
return (<span>Home</span>)
}
const B=()=>{
return (<span>这是B</span>)
}
const c=()=>{
return (<span>这是C</span>)
}
export default DefualtRouter
到此为止react也快学习的差不多了
|