I want to trigger a function whenever the url contains a specific keyword. Any idea on how this can be done?
NOTE : It can be done separately for each route, but that would be a tedious solution.
I want to trigger a function whenever the url contains a specific keyword. Any idea on how this can be done?
NOTE : It can be done separately for each route, but that would be a tedious solution.
You basically want to listen for @@router/LOCATION_CHANGE action type to be dispatched, or whichever the action type is for your version of react-router.
Then use a regex or some kind of matcher.
const url = www.google.com/routeParam
const newRegex = new RegExp(/routeParam/, "gi");
const hasKeyWord = url.match(newRegex);
if (hasKeyWord) {
console.log("// ... we can do function here")
}