gpt4 book ai didi

javascript - 如何在React的render()中导航到react-router-1.0.3中的组件之外?

转载 作者:行者123 更新时间:2023-11-28 06:21:58 25 4
gpt4 key购买 nike

我想在react-router-1.0.3中的渲染函数中路由到另一个路径。我可以通过提供链接来重定向用户:

render(
<Link to={`/${this.props.params.projectSlug}/`}>
Please follow this link to access your workspace.
</Link>
)

但我似乎无法以编程方式转发到此链接。我尝试过:

render(
<Router history={browserHistory} routes=
{`/${this.props.params.projectSlug}/`}/>
)

如何以编程方式转发到react-router 1.0.3中的相对路径?

最佳答案

如果您不介意,请尝试将路由器升级到最新版本;
然后,他们严格明确了怎么做here .

// Your main file that renders a <Router>:
import { Router, browserHistory } from 'react-router'
import routes from './app/routes'

render(
<Router history={browserHistory} routes={routes} />,
mountNode
)

&

// Somewhere like a Redux middleware or Flux action:
import { browserHistory } from 'react-router'

// Go to /some/path.
browserHistory.push('/some/path')

// Go back to previous location.
browserHistory.goBack()

关于javascript - 如何在React的render()中导航到react-router-1.0.3中的组件之外?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35444099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com