How to set the DefaultRoute to another Route in React Router

前端 未结 11 1206
心在旅途
心在旅途 2020-12-13 02:11

I have the following:

  
    
            


        
11条回答
  •  醉梦人生
    2020-12-13 02:41

    I was incorrectly trying to create a default path with:

    
    
    

    But this creates two different paths that render the same component. Not only is this pointless, but it can cause glitches in your UI, i.e., when you are styling elements based on this.history.isActive().

    The right way to create a default route (that is not the index route) is to use :

    
    
    

    This is based on react-router 1.0.0. See https://github.com/rackt/react-router/blob/master/modules/IndexRedirect.js.

提交回复
热议问题