Reactjs 为什么React Router不更改URL更改的视图?
我一直遵循本教程创建react项目。本教程创建了多个包含简单示例文本的react组件。这将允许测试react路由器dom 作为简单组件的示例,所有其他组件都是类似的Reactjs 为什么React Router不更改URL更改的视图?,reactjs,react-router-dom,Reactjs,React Router Dom,我一直遵循本教程创建react项目。本教程创建了多个包含简单示例文本的react组件。这将允许测试react路由器dom 作为简单组件的示例,所有其他组件都是类似的 import React, { Component } from 'react' export default class Cart extends Component { render() { return ( <div> <h3>Hello From Cart&l
import React, { Component } from 'react'
export default class Cart extends Component {
render() {
return (
<div>
<h3>Hello From Cart</h3>
</div>
)
}
}
import React,{Component}来自“React”
导出默认类Cart扩展组件{
render(){
返回(
车上的你好
)
}
}
组件使用react路由器显示,该路由器根据url切换显示的组件
class App extends React.Component {
render() {
return (
<React.Fragment>
<NavBar/>
<Switch>
<Route path="/details" Component={Details} />
<Route path="/cart" Component={Cart} />
<Route path="/" Component={ProductList} />
<Route Component={Default} />
</Switch>
</React.Fragment>
);
}
}
类应用程序扩展了React.Component{
render(){
报税表(
);
}
}
此外,为了避免混淆,我的浏览器路由器正在从index.js重新填充我的应用程序组件
ReactDOM.render(
<Router>
<App />
</Router>
, document.getElementById('root'));
ReactDOM.render(
但是,显示的是:
请帮我解决这个问题,谢谢。我意识到我的错误,我在路由中有“Component={}”,当它应该是“Component={}”(小写字母“c”)。我为所有有相同问题的人发这篇文章。我意识到我的错误,我在路由中有“Component={}”,当它应该是“Component={}”(小写字母“c”)。我为所有有相同问题的人发布此帖子。对不起,您是否将购物车组件导入了应用程序文件?是的,对不起,我没有列出,我的所有组件都已导入。在我决定使用路由器对其进行分段之前,页面一直在显示这些组件。对不起,您是否将购物车组件导入了应用程序文件?是的,对不起,我没有列出,我所有的c组件被导入。页面一直在显示它们,直到我决定用路由器将其分段。