我已经使用 react 和 firebase 构建了测试应用程序并将其部署到 Github Pages。当在 localhost 上一切正常时,但由于某种原因部署时,默认页面(起始页面)不会在该页面上呈现组件。这是我的代码,它位于无状态功能组件 App.js 中。以防万一:( routes.LANDING ="/" )。
<BrowserRouter>
<React.Fragment>
<Navigation />
<Route exact path={routes.LANDING} component={Landing} />
<Route exact path={routes.SIGN_UP} component={SignUp} />
<Route exact path={routes.SIGN_IN} component={SignIn} />
<Route exact path={routes.PASSWORD_FORGET} component={PasswordForget} />
<Route exact path={routes.HOME} component={Home} />
<Route exact path={routes.ACCOUNT} component={Account} />
</React.Fragment>
</BrowserRouter>
据我所知,在使用 react-router 的情况下,我的https://d-ivashchuk.github.io/firebaseApp/将呈现 Landing 组件。相反,我什么也没得到,否则所有链接和路由都按预期工作。
感谢您的任何帮助和建议!
看来问题出在路由器的相对路径上。因为您的单页 web 应用程序托管在 /firebaseApp/ 上,加载https://d-ivashchuk.github.io/firebaseApp/将永远不会显示应该显示在“/”上的组件。您可以将其更改为“/firebaseApp/”,但它会破坏您本地版本的应用程序。在这个确切的问题上有一个 create-react-app 线程:
https://github.com/facebook/create-react-app/issues/1765
为了使 react-router 在开发模式下呈现具有 '/' 路径的页面,该组件的路由应使用环境变量,并且
<Route path={process.env.PUBLIC_URL + '/'}>
在部署到 GH 页面时看起来像这样。
作为记录,firebase 有自己的网站托管服务,您可以使用它应该与 react-router 一起使用。https://firebase.google.com/docs/hosting/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句