Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.
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

@leidegre

Description

@leidegre

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions