![React router example project](https://kumkoniak.com/86.jpg)
![react router example project react router example project](https://www.split.io/wp-content/uploads/2021/02/blog-Blue-React.png)
In the third highlight we changed the boolean to compare the state currentPath instead of the current URL, this is just for clarity as the purpose of the state to re-render the component has already been achieved, the component would still work with the window pathname as we have set currentPath to be equal to it anyways. Import React from "react" import ColorSelect from "./components/ColorSelect" import Translate from "./components/Translate" import Accordion from "./components/Accordion" import Search from "./components/Search" const showAccordion = ( ) =>, ) return currentPath = path ? children We create a new function that returns our Accordion component if our location condition is met, and then call that function in the return section of the app.
![react router example project react router example project](https://i.stack.imgur.com/96IwW.png)
For example let us re-work our App.js file to try this out. Now that we know we can check the property we can use that knowledge to hide or show content based on the value of this property.
![react router example project react router example project](https://cdn.auth0.com/blog/hub/code-samples/spa/react-typescript/react-router-6-basic-authentication.png)
![react router example project react router example project](https://miro.medium.com/max/734/1*j1f042G7d_dkaKxcL0Gizw.gif)
There is a global variable exposed to JavaScript code called window, which has various properties, one of which is window.location.Īnd then within that property we can see another very important property called pathname Showing Content Based On Pathname In short, in a browser, each tab represents a Window, and each window contains a DOM document (a web page). One of the things that is fundamental to understand is the window.location read only property of the window interface. For example if you don’t want to have to update your application when the React-Router library makes a breaking change, which is about once a year.įor our sample we are going to take our Widgets application that we have been working on and create a manual navigation between our different widgets. However there are times when you may not want to use this library. The React-Router library is by far the most popular way to navigate around a React application.
![React router example project](https://kumkoniak.com/86.jpg)