Get parameters outside the component

I would like to get the current parameters outside the component, and as far as I can tell, React Router does not provide a convenient way to do this.

Sometime earlier than 0.13, the router had getCurrentParams (), which I used.

Now the best thing I can understand:

// Copy and past contents of PatternUtils into my project var PatternUtils = require('<copy of PatternUtils.js>') const { remainingPathname, paramNames, paramValues } = PatternUtils.matchPattern( "<copy of path pattern with params I am interested in>", window.location.pathname); 

Is there a way to do this using React router?

+7
react-router
source share
1 answer

you can use matchPath :

 import { matchPath } from 'react-router' const { params }= matchPath(window.location.pathname, { path: "<copy of path pattern with params I am interested in>" }) 
0
source share

All Articles