我正在努力寻找解决此问题的方法。 我正在使用 create-react-app,在运行 npm build 之后,我希望能够在浏览器中使用文件位置的“双击”打开 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 得到它,当我检查它显示里面有评论时。
我试图在不使用任何类型的服务器的情况下让应用程序在浏览器中运行。只需在浏览器中打开 build 文件夹中的 index.html。
注意:一切都在开发中完美运行
非常感谢。
最佳答案
我发现使用 <HashRouter>
而不是 <Router>
固定它。
非常感谢
关于javascript - 我正在使用 create-react-app,我需要在没有服务器的情况下直接在浏览器中打开 build/index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45878542/