Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

There needs to be a way to get at the params of a CHANGE_LOCATION action #297

Closed
leidegre opened this issue Feb 23, 2016 · 5 comments
Closed

Comments

@leidegre
Copy link

The routes define an important aspect of the route namely the params. I've looked around and for this to work the routes need to be passed to the middleware.

Internally the way react-router does this is beyond me atm but I think this is doable. I'll update this issue with my progress and maybe provide a pull request for it.

The reason I think this is important is that the routes already define this structure and the logic for parsing routes in defined in react-router replicating this work (while it's easy to grep some like an ID from an URI) I'd very much prefer if these things were not dependant on each other.

In essence this is what I want.

import matchRoutes from 'react-router/lib/matchRoutes'

const routeConfig = [
  ...
]

const routeParamsMiddleware = store => next => action => {
  if (action.type === '@@router/LOCATION_CHANGE') {
    matchRoutes(routeConfig, action.payload, (error, state) => {
      action.routes = state.routes
      action.params = state.params
      next(action)
    })
    return
  }
  return next(action)
}

The obvious caveat is that this depends on an private react-router API, matchRoutes...

@PhilWaldmann
Copy link

👍

@taion
Copy link
Member

taion commented Feb 23, 2016

Check the other issues before opening new ones – #246

This is excluded by design.

@taion taion closed this as completed Feb 23, 2016
@leidegre
Copy link
Author

@taion I did look but I did not find one. Thanks for pointing it out.

@gaearon
Copy link
Member

gaearon commented Feb 23, 2016

You might want to look at https://github.com/acdlite/redux-router instead.

@leidegre
Copy link
Author

@gaearon Thanks, that looks a lot like what I want. I'll have to take it for a spin.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants