Skip to content

Instantly share code, notes, and snippets.

@MeetMartin
Created October 16, 2018 10:32
Show Gist options
  • Save MeetMartin/34ae1d952ff62c22cd95edf3585f3b56 to your computer and use it in GitHub Desktop.
Save MeetMartin/34ae1d952ff62c22cd95edf3585f3b56 to your computer and use it in GitHub Desktop.
import React from 'react';
import { BrowserRouter as Router, Link } from 'react-router-dom';
import Routes from './Routes';
/**
* Turns URL path into router basename by removing everything after the last slash
* @param {string} path URL path, probably window.location.pathname
* @returns {string} final basename
*/
const getBasename = path => path.substr(0, path.lastIndexOf('/'));
/**
* Base Template component holding the basic web application
* @returns {JSX}
*/
const App = () => (
<Router basename={getBasename(window.location.pathname)}>
<main>
<Routes />
</main>
</Router>
);
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment