How to get current route in react-router 2.0.0-rc5

后端 未结 9 1280
无人及你
无人及你 2020-12-08 18:05

I have a router like below:


    
        
          


        
9条回答
  •  轮回少年
    2020-12-08 18:53

    You could use the 'isActive' prop like so:

    const { router } = this.context;
    if (router.isActive('/login')) {
        router.push('/');
    }
    

    isActive will return a true or false.

    Tested with react-router 2.7

提交回复
热议问题