Routers: The Comeback

As we've progressed further into React I am relearning how to accomplish some tasks that I knew how to do in Node but is done a bit differently now. For example, routing is not a new concept and is something I have done before in previous projects but React handles routes a little differently than Node. Fortunately, both are Javascript so nothing is radically different.


Inside of the index.js file I've placed this BrowserRouter which I imported at the top of the page. I then used the syntax I found from the documentation to make a list of endpoints I wanted. The most simple route, the root path, on the bottom to allow the file to read every preceding path as well. The first path here is a dynamic route meaning the :id can change but still render the same layout.

I've accomplished all of this before but I did get quite stuck on figuring out where to put my code in React. After enough trial and error I finally moved it into the right spot, linked the component files, and saw my hard work displayed in the browser!

Comments