Node.js 如何使404路由在React路由器中工作?
我正在尝试使用react路由器创建404路由,但它不起作用Node.js 如何使404路由在React路由器中工作?,node.js,reactjs,react-router,Node.js,Reactjs,React Router,我正在尝试使用react路由器创建404路由,但它不起作用 我尝试了和,并用包装了我的所有路线。我认为问题在于您拥有的交换机块的数量。你最好只有一个。 由于每条路由都是精确的,因此您可以将开关组件子级压缩为 类应用程序扩展组件{ render(){ 返回( ); } } 这将允许404页面成为一个包罗万象的页面,如果在整个开关块中没有一条路由匹配。我认为问题在于您拥有的开关块的数量。你最好只有一个。 由于每条路由都是精确的,因此您可以将开关组件子级压缩为 类应用程序扩展组件{ render()
我尝试了
和
,并用包装了我的所有路线。我认为问题在于您拥有的交换机
块的数量。你最好只有一个。
由于每条路由都是精确的,因此您可以将开关
组件子级压缩为
类应用程序扩展组件{
render(){
返回(
);
}
}
这将允许404页面成为一个包罗万象的页面,如果在整个开关块中没有一条路由匹配。我认为问题在于您拥有的开关块的数量。你最好只有一个。
由于每条路由都是精确的,因此您可以将开关
组件子级压缩为
类应用程序扩展组件{
render(){
返回(
);
}
}
这将允许404页面成为一个包罗万象的页面,如果在整个开关块中没有任何路由匹配。尝试
@YahyaAhmed I did。没用我试过了。不起作用
class App extends Component {
render() {
return (
<Provider store={store}>
<Router>
<div className="App">
<Header />
<Switch>
<Route exact path="/" component={Landing} />
<Route exact path="/login" component={Login} />
<Route exact path="/register" component={Register} />
<Route exact path="/profiles" component={Profiles} />
<Route exact path="/profile/:id" component={Profile} />
<Switch>
<PrivateRoute exact path="/dashboard" component={Dashboard} />
</Switch>
<Switch>
<PrivateRoute exact path="/posts" component={Posts} />
</Switch>
<Switch>
<PrivateRoute exact path="/post/:id" component={Post} />
</Switch>
<Switch>
<PrivateRoute
exact
path="/create-profile"
component={CreateProfile}
/>
</Switch>
<Switch>
<PrivateRoute
exact
path="/edit-profile"
component={EditProfile}
/>
</Switch>
<Route path="*" component={PageNotFound} />
</Switch>
<Footer />
</div>
</Router>
</Provider>
);
}
}
const PrivateRoute = ({ component: Component, auth, ...rest }) => (
<Route
{...rest}
render={props =>
auth.isAuthenticated === true ? (
<Component {...props} />
) : (
<Redirect to="/login" />
)
}
/>
);