How to do a redirect to another route with react-router?

前端 未结 6 2196
眼角桃花
眼角桃花 2020-12-07 13:37

I am trying to do A SIMPLE using react-router ( version ^1.0.3 ) to redirect to another view and I am just getting tired.

import React from          


        
6条回答
  •  感情败类
    2020-12-07 14:26

    How to do a redirect to another route with react-router?

    For example, when a user clicks a link Click to route react-router will look for / and you can use Redirect to and send the user somewhere else like the login route.

    From the docs for ReactRouterTraining:

    Rendering a will navigate to a new location. The new location will override the current location in the history stack, like server-side redirects (HTTP 3xx) do.

    import { Route, Redirect } from 'react-router'
    
     (
      loggedIn ? (
        
      ) : (
        
      )
    )}/>
    

    to: string, The URL to redirect to.

    
    

    to: object, A location to redirect to.

    
    

提交回复
热议问题