我正在使用 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 或任何服务器.我还希望我的应用程序的路线和功能能够在这种情况下工作。 我一直在对此事进行一些研究,但找不到太多。我想知道是否有可能,如果有人有任何链接甚至解决方案可以分享,以防我遗漏某些东西。 将不胜感激。

更新:

我正在使用 ubuntu 17。我在 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 得到它,当我检查它正在显示其中的评论。 我试图在不使用任何类型的服务器的情况下让应用程序在浏览器中运行。只需从浏览器中的构建文件夹中打开 index.html。

注意:一切都在开发中完美运行

非常感谢。

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

非常感谢