重拾 react
由于最近一段时间一直在使用vue做项目,最近打算重拾react,在此记录react的点滴学习,实时更新
生命周期
routerWillLeave 路由跳转前确认
return false
取消本次跳转return
返回提示信息,在离开Route前提示用户进行确认
1
2
3
4
5
6
7
8
9
10import { Lifecycle } from 'react-router'
const Home = React.createClass({
// 假设 Home 是一个 route 组件,它可能会使用
// Lifecycle mixin 去获得一个 routerWillLeave 方法。
mixins: [ Lifecycle ],
routerWillLeave(nextLocation) {
if (!this.state.isSaved)
return 'Your work is not saved! Are you sure you want to leave'
},
})
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Comment
DisqusValine