First you must know that Switch and exact doesn't exist in v6 anymore. Instead of Switch you need to import Routes in v6.
As for exact, in v6 the matching by default is only if the whole path is matching and not just the begining (which is the behavior in v5.) So in v6 you don't need to add exact.
If you do want that behavior that it navigates even if just the begining of the path matches, you can add /* at the end of the path.
发布评论
评论(1)
这是您在
app
组件中需要的代码,但是您也可能需要对其他组件应用一些更改。 (请查看下面的链接)首先,您必须知道
switch
和exact
在V6中不存在。您需要在V6中导入 而不是
switch
。至于
精确
,在v6中,默认匹配仅在整个路径是匹配的,而不仅仅是开始(这是V5中的行为)。因此,在V6中,您无需添加精确。如果您确实想要它导航的行为,即使只是路径的开始匹配,也可以在路径末端添加
/*
。查看此链接以获取有关更改的更多信息: https> https:htttps //reactrouter.com/docs/en/v6/upgrading/v5
This is the code you need in the
App
component , but you may also need to apply some changes on other components. (check out the link below)First you must know that
Switch
andexact
doesn't exist in v6 anymore.Instead of
Switch
you need to importRoutes
in v6.As for
exact
, in v6 the matching by default is only if the whole path is matching and not just the begining (which is the behavior in v5.) So in v6 you don't need to add exact.If you do want that behavior that it navigates even if just the begining of the path matches, you can add
/*
at the end of the path.Check out this link for more information about the changes: https://reactrouter.com/docs/en/v6/upgrading/v5