简体   繁体   中英

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.

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.

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).

  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)

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? I want to make use of the params and link with an absolute path with id.

Thanks

For the Question 3, I have figured out the method to access the params

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,
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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