react-router-dom 直接访问时,路由不会通过 Firebase 部署在 Safari 中呈现 link
react-router-dom route not rendering in Safari via Firebase deploy when visiting direct link
使用react-native-dom时如下:
// index.js
import React from 'react'
import ReactDOM from 'react-dom'
import App from './components/App'
import registerServiceWorker from './registerServiceWorker'
ReactDOM.render(<App/>, document.getElementById('root')) registerServiceWorker()
// 应用程序
render() {
return (
<div className="appContainer">
<Router>
<div className="container">
<Header/>
<Switch>
<Route exact path='/' component={Website}/>
<Route path='/docs' component={Doc}/>
</Switch>
<Footer/>
</div>
</Router>
</div>
)
}
在本地主机上,甚至在 Chrome 和 FF 上生产时,一切都按预期工作,但如果直接链接到 http://mysite/docs
或导航到路由然后刷新浏览器。
我只收到:This file does not exist and there was no index.html found in the current directory or 404.html in the root directory.
。
我唯一可以添加的其他信息是这是一个 Firebase 托管站点(我不认为这是根本问题,但值得注意)...
有没有人经历过或有任何见解。我没有发现任何特定的浏览器问题......
好的,对于遇到类似问题的任何人,我将把它留在这里:
对于您需要在导航之外点击的任何路线(直接 link 路线),在 firebase.json
中将其设置为这样
"hosting": {
"public": "build",
"rewrites": [
{
"source": "/docs",
"destination": "/index.html"
},
{
"source": "/other",
"destination": "/index.html"
}
// or for a catch all
// {
// "source": "**",
// "destination": "/index.html"
// }
]
}
使用react-native-dom时如下:
// index.js
import React from 'react'
import ReactDOM from 'react-dom'
import App from './components/App'
import registerServiceWorker from './registerServiceWorker'
ReactDOM.render(<App/>, document.getElementById('root')) registerServiceWorker()
// 应用程序
render() {
return (
<div className="appContainer">
<Router>
<div className="container">
<Header/>
<Switch>
<Route exact path='/' component={Website}/>
<Route path='/docs' component={Doc}/>
</Switch>
<Footer/>
</div>
</Router>
</div>
)
}
在本地主机上,甚至在 Chrome 和 FF 上生产时,一切都按预期工作,但如果直接链接到 http://mysite/docs
或导航到路由然后刷新浏览器。
我只收到:This file does not exist and there was no index.html found in the current directory or 404.html in the root directory.
。
我唯一可以添加的其他信息是这是一个 Firebase 托管站点(我不认为这是根本问题,但值得注意)...
有没有人经历过或有任何见解。我没有发现任何特定的浏览器问题......
好的,对于遇到类似问题的任何人,我将把它留在这里:
对于您需要在导航之外点击的任何路线(直接 link 路线),在 firebase.json
"hosting": {
"public": "build",
"rewrites": [
{
"source": "/docs",
"destination": "/index.html"
},
{
"source": "/other",
"destination": "/index.html"
}
// or for a catch all
// {
// "source": "**",
// "destination": "/index.html"
// }
]
}