react router v4
当父子路由嵌套的时候必须写完整路径,如下
<Route path='/App' component={App} />
<Route path='/App/task' component={Task} />
不能在父组件里面写相对路径,如下
const App = ()=>{
return <div>
<Route path='/task' component={Task} />
</div>
}
<Route path='/App' component={App} />
this.props 里面有history,location,match等属性,history类似于浏览器窗口中的history对象
history对象常用属性
-
location(object类型),当前的位置,常用属性有pathname是url路径,search是url中的查询字符串 -
push(function 类型),在 hisotry 栈顶加入一个新的地址 -
replace( function 类型),替换history 堆栈中的当前地址