简体   繁体   English

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

[英]How can I navigate outside of components in react-router-1.0.3 in React's render()?

I want to route to another path in the render function in react-router-1.0.3. 我想路由到react-router-1.0.3中的render函数中的另一个路径。 I can redirect the user by providing a link using: 我可以使用以下方法提供链接来重定向用户:

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

But I cant seem to programmatically forward to this link. 但是我似乎无法以编程方式转发到此链接。 I tried: 我试过了:

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

How can I programmatically forward to a relative path in react-router 1.0.3? 如何以编程方式转发到react-router 1.0.3中的相对路径?

Try upgrade router to the latest version if you don't mind; 如果您不介意,请尝试将路由器升级到最新版本。
Then, they strictly clarify how to do it 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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM