Javascript 反应路线不';t渲染我的组件并给出404错误

Javascript 反应路线不';t渲染我的组件并给出404错误,javascript,reactjs,Javascript,Reactjs,我一直在练习如何使用最新的模块版本,所以我目前正在尝试使用react路由器dom。它不会以精确的路径呈现页面组件,而是在主页上呈现 我尝试使用其他版本的react router dom,但仍然得到相同的结果 //App.js file import React from 'react'; import {BrowserRouter as Router, Route} from 'react-router-dom'; function App() { return ( &

我一直在练习如何使用最新的模块版本,所以我目前正在尝试使用react路由器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>
        )

}
//App.js文件
从“React”导入React;
从“react Router dom”导入{BrowserRouter as Router,Route};
函数App(){
返回(
//不渲染localhost://8080/shop,但在localhost://8080,它将呈现商店页面
)
}
导出默认应用程序;
功能商店(){
返回(
商店
)
}

它应该呈现适当的组件,但给出了404错误。我还发现通常有一个自动完成选项(在我以前的版本上尝试路线时,它会在我的IDE中显示“component,components,path..”,但在这里它不会显示任何内容。是否可能路线未被识别?

尝试在路线中添加“精确”道具

<Route exact path="/shop" component={Shop}/> 


这是一个解释。

关于没有在任何地方定义。我准确地运行了您的代码,但包含了关于页面的一个函数。路由器为我工作。主页上没有显示任何内容,/shop有h3标记表示商店,/About有h3标记表示大约


index.js正在调用该应用程序吗?您对此进行了任何修改吗?

在我看来,问题不在于此代码,因为在codesandbox上,此模板起作用,请尝试再次创建react应用程序并重新安装依赖项。您可以将此代码添加到codesandbox,以便我可以帮助您。