繁体   English   中英

我正在使用create-react-app,需要在没有服务器的情况下直接在浏览器中打开build / index.html

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

我正在努力寻找解决此问题的方法。 我正在使用create-react-app,运行npm build之后,我希望能够从文件位置使用“ doubleclick”在浏览器中打开index.html,而无需npm或任何服务器。 我还希望我的应用程序的路由和功能在这种情况下能够正常工作。 我一直在对此事进行研究,但找不到很多。 我想知道是否有可能,是否有人可以分享任何链接甚至解决方案,以防万一我丢失了某些东西。 将不胜感激。

更新:

我正在使用ubuntu17。src / App.js中的主要路由如下所示:

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

我的index.js看起来像这样:

import App from './component/App';


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

运行npm run build并在浏览器中打开build / index.html,它是蓝色的(背景),所以当我检查它的内部带有注释时,它会出现一些CSS。 我正在尝试使该应用程序在浏览器中运行,而不使用任何类型的服务器。 只需从浏览器的build文件夹中打开index.html。

注意:一切都可以在dev中完美运行

提前谢谢了。

我发现使用<HashRouter>而不是<Router>修复了该问题。

非常感谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM