Search code examples
javascriptnode.jsreactjswebpackcreate-react-app

I'm using create-react-app and I need to open build/index.html in browser directly without a server


I'm struggling to find the solution to this issue. I'm using create-react-app and after running npm build I want to be able to open index.html in browser with 'doubleclick' from file location, without the need of npm or any server. I also want my routes and functionality of the app to work in this scenario. I've been doing some research on the matter but couldn't find much. I would like to know if it's possible and if anyone has any links or even solutions to share in case I'm missing something. Would be greatly appreciated.

Update:

I'm using ubuntu 17. My main route in src/App.js looks like so :

class App extends React.Component {
  render(){
    return(
      <Router basename="/">
        <Switch>
            <Route exact path="/" component={LoginComponent}/>
            <Route path="/app" component={AppLayout}/>
        </Switch>
      </Router>
    );
  }
}

And my index.js looks like so:

import App from './component/App';


ReactDOM.render(<App />, document.getElementById('root'));

After running npm run build and open build/index.html in browser, it's blue (the background) so some css gets to it, when i inspect it's showing with the comment inside it. I'm trying to get the app working in browser without using any kind of server. Just by opening index.html from build folder in the browser.

Note: everything works perfectly in dev

Many thanks in advance.


Solution

  • I found that using <HashRouter> instead of <Router> fixed it.

    Many thanks