React Router - how to constrain params in route matching?

后端 未结 2 1975
暖寄归人
暖寄归人 2021-02-01 02:02

I don\'t really get how to constrain params with, for example a regex.
How to differentiate these two routes?

  
    

        
2条回答
  •  长情又很酷
    2021-02-01 02:35

    React-router v4 now allows you to use regexes to match params -- https://reacttraining.com/react-router/web/api/Route/path-string

    const NumberRoute = () => 
    Number Route
    ; const StringRoute = () =>
    String Route
    ;

    More info: https://github.com/pillarjs/path-to-regexp/tree/v1.7.0#custom-match-parameters

提交回复
热议问题