React router Switch behavior

后端 未结 1 1601
日久生厌
日久生厌 2020-12-13 08:44

(react-router-dom version: 4.1.1)

I have working routes set up, but I\'m a bit confused about why the was necessary:

1条回答
  •  借酒劲吻你
    2020-12-13 09:14

    returns only one first matching route.

    exact returns any number of routes that match exactly.

    For example:

    
      
      
      
    
    
    

    If the Missing component was not inside a , it would be returned on every single route.

    With exact, the "/animals" route will not catch every route containing "/animals" such as "animals/fish".

    Without exact, the "/animals/fish" route will also return the Fish component for "animals/fish/cod", "/animals/fish/salmon", etc.

    Being outside the statement and without exact, the Order component is rendered on every path containing "/animals".


    Usually, if you're not using exact you would use a wildcard, so you don't return random pages.

    0 讨论(0)
提交回复
热议问题