React Router - how to constrain params in route matching?

后端 未结 2 1976
暖寄归人
暖寄归人 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:36

    I'm not sure if this is possible with React router at the moment. However there's a simple solution to your problem. Just do the int/alpha check in another component, like this:

    
        
    
    
    const Child0 = (props) => {
        let n = props.params.index;
        if (!isNumeric(n)) {
            return ;
        } else {
            return ;
        }
    }
    

    * Note that the code above does not run, it's just there to show what I mean.

提交回复
热议问题