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

前端 未结 6 2195
眼角桃花
眼角桃花 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 13:59

    For the simple answer, you can use Link component from react-router, instead of button. There is ways to change the route in JS, but seems you don't need that here.

    
      Click to login
    
    

    To do it programmatically in 1.0.x, you do like this, inside your clickHandler function:

    this.history.pushState(null, 'login');

    Taken from upgrade doc here

    You should have this.history placed on your route handler component by react-router. If it child component beneath that mentioned in routes definition, you may need pass that down further

提交回复
热议问题