davidmfoley / react-router-modal

Simple modals for react-router 4
MIT License
153 stars 20 forks source link

Parent path with param #25

Open Sexual opened 6 years ago

Sexual commented 6 years ago

Is there a way for the parent path to have a param in it like the example below?

path="/image/:id/comments" parentPath="/image/:id"

Doing this does not work, hence I believe that the parent path logic isn't the same as the one used in react router as when you click the backdrop, it will redirect to /image/:id without the actual ID.

davidmfoley commented 6 years ago

Good feature request. In the meantime, there is an undocumented workaround: you can provide a function for parentPath and it will be invoked with the current Match and the result will be used as the parentPath.

Sexual commented 6 years ago

@davidmfoley indeed doing something like the below option does work.

parentPath={(match) => `/image/${match.params.id}`}

I'll look into getting a pull request done with a solution for it.