javascript - React 路由不渲染我的组件并给出 404 错误
问题描述
我一直在练习如何使用最新的模块版本,所以我目前正在尝试使用 react-router-dom。它不会在确切的路径上呈现页面组件,而是在主页上呈现。
我尝试使用其他版本的 react-router-dom,但仍然得到相同的结果。
//App.js file
import React from 'react';
import {BrowserRouter as Router, Route} from 'react-router-dom';
function App() {
return (
<Router>
<div>
<Route path="/shop" component={Shop}/>
//doesn't render at localhost://8080/shop, but at localhost://8080, it renders the Shop page
<Route path="/about" component={About}/>
</div>
</Router>
)
}
export default App;
function Shop() {
return (
<div>
<h3>
Shop
</h3>
</div>
)
}
它应该呈现适当的组件,但给出 404 错误..我还发现通常有一个自动完成选项(它在我的 IDE 上显示'组件,组件,路径..'在我以前的版本上尝试路由时,但在这里它没有显示任何东西。是否有可能无法识别路线?
解决方案
推荐阅读
- python-2.7 - Pylearn2安装报错如何解决?
- json - json格式的Kubernetes configmap错误
- mysql - SQL 中的 Group By 函数有问题
- xcode - 上传到 Apple App Store “无效的自定义意图”
- php - 如何在 PHP 中从另一个位置(Windows + 磁盘 E)访问图像/视频?
- express - graphql mongoose 返回 null
- javascript - 使用 JSON 数据控件表达
- html - 为什么一起使用 ngIf 和 ViewChild 时出现未定义的错误
- sql-server - 在 SQL Server 中迭代没有循环的记录
- xml - linq to xml 查询需要正确的语法