简体   繁体   English

React路由器获取组件外的当前路由

[英]React router get current route outside component

I am now using fluxible with react-router, I want to perform action and then redirect after the callback. 我现在使用fluxable与react-router,我想执行操作然后在回调后重定向。

In the action, the action context has no router and fail to change the route after the action. 在操作中,操作上下文没有路由器,并且在操作后无法更改路由。

I have tried to find example but I can only found using browserHistory. 我试图找到示例,但我只能找到使用browserHistory。

I can now push the browserHistory but somehow I can't find the current path. 我现在可以推送浏览器历史记录,但不知怎的,我找不到当前的路径。 (because my new path is the depends on the current path /:id/profile, and then I want to redirect to /:id/details/:version), So I need to get back /:id/details before I append the version). (因为我的新路径取决于当前路径/:id / profile,然后我想重定向到/:id / details /:version),所以我需要在追加之前取回/:id / details版)。

  1. How to find the current route in the action where I can only access the action context without router instance? 如何在我只能访问没有路由器实例的操作上下文的操作中找到当前路由?

  2. Sometimes my react router works on server side but not client side. 有时我的反应路由器在服务器端工作,但不在客户端工作。 It will show when I refresh the page but 404 when in client side only.( I guess because I am using the relative link) 它将在我刷新页面时显示,但仅在客户端时显示404。(我猜因为我使用的是相对链接)

Does react router support relative link in the ? 反应路由器是否支持相对链接?

  1. How to pass the params and router in the stateless component? 如何在无状态组件中传递参数和路由器? In the stateless component, I can only access props but not context. 在无状态组件中,我只能访问道具而不能访问上下文。 So I can't access the router or params? 所以我无法访问路由器或params? I want to make use of the params and link with an absolute path with id. 我想利用params并使用带有id的绝对路径进行链接。

Thanks 谢谢

For the Question 3, I have figured out the method to access the params 对于问题3,我已经找到了访问参数的方法

In fact, the second argument in the stateless component is context. 实际上,无状态组件中的第二个参数是上下文。 I have pass the params and obtain there. 我已经通过了参数并在那里获得了。

eg 例如

const CompanyDetail = (props, context) => {

}
CompanyDetail.contextTypes = {
  params: PropTypes.object,
};

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

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