I have multiple routes in an array like:
- /app/manual/:id
- /app/manuals/:id
- /app/feedback
- ...
In my react.js application I now want to match the location.pathname with the according path in my array and then I want to get the title of the array.
routes.find(x => x.path === location.pathname)?.title;
The problem is that with my solution only paths without any parameters get matched. So /app/manual/manual4 would not get matched while /app/feedback would get matched
I tried doing it with regex, but without any success.
routes.find(x => location.pathname.match(new RegExp(".*" + x.path+ "/.*")))?.title