[英]How to do Client side routing using react router 1.0.x in a click handler?
我有一个单页应用程序。 我可以使用react-router提供的<Link>
标签使用客户端路由器。
<Link to='/nextRoute'>next</Link
但是,如果我需要更改点击处理程序的路由,该怎么办? (在离开之前,我有一些事情要做)
使用window.location.assign
将导致整个事情再次从服务器获取,但是我需要使用客户端路由器。
我相信1.0.x使用了历史记录包。
您必须检查使用的是哪个版本的历史记录,但是从文档中可以看到:
// Push a new entry onto the history stack.
history.push('/home')
// Replace the current entry on the history stack.
history.replace('/profile')
// Push a new entry with state onto the history stack.
history.push({
pathname: '/about',
search: '?the=search',
state: { some: 'state' }
})
// Change just the search on an existing location.
history.push({ ...location, search: '?the=other+search' })
// Go back to the previous history entry. The following
// two lines are synonymous.
history.go(-1)
history.goBack()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.