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

前端 未结 6 2215
眼角桃花
眼角桃花 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:09

    Easiest solution for web!

    Up to date 2020
    confirmed working with:

    "react-router-dom": "^5.1.2"
    "react": "^16.10.2"
    

    Use the useHistory() hook!

    import React from 'react';
    import { useHistory } from "react-router-dom";
    
    
    export function HomeSection() {
      const history = useHistory();
      const goLogin = () => history.push('login');
    
      return (
        
                    
            
              
    ); }

提交回复
热议问题