Answer the question
In order to leave comments, you need to log in
How to correctly check the url for a match?
I check like this
const routes = {
main: '/',
news: '/news',
staticNews: '/news/:id',
page: '/pages/:id',
};
const location = useLocation();
Object.values(routes).find((route) => location.pathname === route) // проверка на совпадение url
Answer the question
In order to leave comments, you need to log in
And you don't have to do it manually. Such urls should be parsed by the router:
https://habr.com/ru/post/329996/
https://github.com/ReactTraining/react-router
and google further
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question