【发布时间】:2020-02-13 01:33:46
【问题描述】:
我正在研究一个使用 React Router 的简单示例。
我使用 create-react-app 创建它
在本地服务器上,每个链接都运行良好 ex) localhost:3000/login、localhost:3000/product 等
部署到我的域后,我在输入链接时收到 404 错误。 例如)myDomain.com/login、myDomain.com/product
在本地服务器上看起来不错,所以我认为源代码没有问题。
然后,当出现 404、403 ... 等页面时,我收到了重定向到 index.html 页面的答案
localhost:3000 和 localhost:3000/index.html 是一样的吗?
在主页(本地主机:3000 或 myDomain.com)上, 渲染得很好。
在 index.html (localhost: 3000 / index.html 或 myDomain.com/index.html) 它只在 {Home} 上方呈现最多 h1 标记。从这里有什么问题吗?
请帮帮我T.T
App.js
class App extends Component{
render(){
return (
<div className="App">
<Header/>
<h1>asd</h1>
<h1>asd</h1>
<Route exact path = "/" component = {Home}/>
<Route path = "/about" component = {About}/>
<Route path = "/event" component = {Event}/>
<Route path = "/qna" component = {QnA}/>
<Route path = "/login" component = {Login}/>
<Route path = "/join" component = {Join}/>
<Route path = "/product" component = {Product}/>
</div>
);
}
}
export default App;
Root.js
const Root = () => {
return (
<BrowserRouter>
<App/>
</BrowserRouter>
);
};
export default Root;
【问题讨论】:
-
你可以在你的应用中访问
/路由吗?
标签: javascript reactjs react-router