How to start react app on specific route in development mode, not from home route, after running command npm start

Viewed 2234

React app starts on localhost:3000 by defult as soon we run command npm start. At the moment I have nothing to show on my home route "/". I want the app start directly from http://localhost:3000/content when I run command npm start. I can't figure out the way to do so. There is a way when we deploy the app on some server, but don't know how to do it development mode?

1 Answers

If you are using react-router you can use the basename prop to set the sub directory

<BrowserRouter basename='/content'>
  <App />
</BrowserRouter>

OR you can redirect / to /content in your Switch block

<Switch>
   <Redirect exact from="/" to="/content" />
   <Route exact path="/content" component={ContentComponent} />
Related