React Router
Last updated: 2020-05-04
Deploy To Subdirectory
Convert all absolute links to relative ones. Base tag works only for relative URLs. In other words, it's required to replace all paths that start with
/to./. Conversion should be applied to all resources and assets. All assets should reside within thesrcfolder.<body> <img src="./assets/logo.svg" /> </body>Setup
homepageinpackage.jsonto/subdir/"homepage": "/subdir/",Add
<base href="%PUBLIC_URL%/">toindex.html. This tag should be placed in the<head>before any other element that uses URLS.<head> ... <base href="%PUBLIC_URL%/" /> <title>React App</title> </head> <body> ... </body>Add router history package
npm install --save history # or yarn add historyAdjust the router
import { createBrowserHistory } from 'history'; ... export const history = createBrowserHistory({ basename: process.env.PUBLIC_URL });Use updated history and basename in router
<Router history={history} basename={'/subdir'}>