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

混江龙づ霸主 提交于 2021-01-28 02:37:49

问题


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.


回答1:


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

Many thanks



来源:https://stackoverflow.com/questions/45878542/im-using-create-react-app-and-i-need-to-open-build-index-html-in-browser-direct

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!