Programmatically Navigate using react-router

前端 未结 8 1321
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 23:07

I am developing an application in which I check if the user is not loggedIn. I have to display the login form, else dispatch an action

8条回答
  •  [愿得一人]
    2020-11-21 23:26

    I was able to use history within stateless functional component, using withRouter following way (needed to ignore typescript warning):

    import { withRouter } from 'react-router-dom';
    
    ...
    
    type Props = { myProp: boolean };
    
    // @ts-ignore
    export const MyComponent: FC = withRouter(({ myProp, history }) => {
    
    ...
    
    })
    

提交回复
热议问题