Site icon The Perpetual Student

React HashRouter

Example code snippet on HashRouter from react-router-dom.  This routing alternative can be used on hosting services such as GitHub pages and other static hosting services.

Implementation

Import HashRouter:


import { HashRouter as Router, Route } from 'react-router-dom';

Example code that goes in render():


<HashRouter>
   <div>
      <Route path="/" component={Home} />
      <Route path="about" component={About} />
      <Route path="teachers" component={Teachers} />
      <Route path="courses" component={Courses} />
   </div>
</HashRouter>

Here’s a link to my Gist if that doesn’t come out correctly.

Drawbacks

A collection of thoughts and issues I’ve found for using HashTag for a website:

Exit mobile version