React router dom get current route3/17/2024 ![]() When using the useLocation hook, we must make sure that the code is running inside a component wrapped by the component. When we click on Home, we get the following result logged to the console:Īnd when we click on Products, we get the following result:Ĭlearly, the pathname property of the object is the current active route. import React from "react" import Home from "./components/Home" import Header from "./components/Header" import Products from "./components/Products" import export default App In the code example below, on line 9, we are logging the value of the location variable to the console. react router dom v5 route event get slug id react router dom functional component react router history. Our app below has two routes: / & /products. We can find out the currently active route using the useLocation hook. Master the fundamentals of React Router in my blog post here.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |