React Router In-Line Scripting

Recently I configured my main website to use React. I wanted to have my logo and web navigation at the top and retain my footer at the bottom of the page for all of the website pages. This left the content area to be dynamic based upon what navigation button was pressed. Content is illustrated in the figure below.

Most tutorials I had seen with React Router required the developer to define a NavBar component I was not too keen on using. Why? My reasoning boils down to preference. The NavBar or "<nav>" component is provided by React. I find it to be an OK solution, but React Router is still required to make the actual nav selection displayable.

NavBar is not needed for the simplicity of what I was trying to do. My website being a little more lightweight will not hurt anything either by not importing it to my app.

Again, the problem to solve was to make meat of the page content dynamic (see the circled area above). I chose to import only React Router into my App.js to solve this issue.

The intent with only using React Router is to use as less code as possible and have great maintainability. Using inline HTML achieved this no problem.

Since I did not use Nav component, the links that React Router recognizes must be declared within the React Router's definition. Since the Nav component is at the top of the page, the react router had to be declared at the page container level.

Each Link defines the route to a page content of a user's navigation choice. The table element with the class name "table" defines the Links that the Router can use later in the script, as seen in the "content" div.

Since Router was defined at an upper HTML level, it also must encapsulate the footer.

Leave a Reply

Your email address will not be published. Required fields are marked *