[英]Can I run index.html with React without npm start and npx create-react-app?
[英]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.