Reactjs 反应路由器4:将页面路由到404页面(如果没有)';与我的路由URL不匹配
当我的URL是Reactjs 反应路由器4:将页面路由到404页面(如果没有)';与我的路由URL不匹配,reactjs,react-router-v4,react-router-dom,Reactjs,React Router V4,React Router Dom,当我的URL是http://localhost:8080/home1但是当我用子路径(http://localhost:8080/home/1)它无法呈现我的未找到的组件,并显示一个空屏幕。有人能告诉我我缺少什么吗? <Switch> <Route exact path="/" component={App}/> <Route path="/home" component={Dashboard}/> <Route component={NotFound}
http://localhost:8080/home1
但是当我用子路径(http://localhost:8080/home/1
)它无法呈现我的未找到的组件,并显示一个空屏幕。有人能告诉我我缺少什么吗?
<Switch>
<Route exact path="/" component={App}/>
<Route path="/home" component={Dashboard}/>
<Route component={NotFound}/>
</Switch>
这就是它应该匹配的方式,因为home1与home不匹配。但在第二个示例中,它正确匹配,然后呈现为未指定的精确值,但假设它仅匹配我的路由器“路径”时工作?第二个例子与我的路径不匹配,所以它应该重定向到404页。我的理解正确吗?你应该在回答中提供解释。
<Switch>
<Route exact path="/" component={App}/>
<Route path="/home" component={Dashboard}/>
<Route path="*" component={NotFound}/>
</Switch>