Programmatically navigate using react router

后端 未结 30 2294
無奈伤痛
無奈伤痛 2020-11-21 05:18

With react-router I can use the Link element to create links which are natively handled by react router.

I see internally it calls t

30条回答
  •  爱一瞬间的悲伤
    2020-11-21 05:23

    Maybe not the best solution but it gets the job done:

    import { Link } from 'react-router-dom';
    
    // create functional component Post
    export default Post = () => (
        
    );

    Basically, a logic tied to one action (in this case a post deletion) will end up calling a trigger for redirect. This is not ideal because you will add a DOM node 'trigger' to your markup just so you can conveniently call it when needed. Also, you will directly interact with the DOM, which in a React component may not be desired.

    Still, this type of redirect is not required that often. So one or two extra, hidden links in your component markup would not hurt that much, especially if you give them meaningful names.

提交回复
热议问题