404 page in REACT

前端 未结 4 1594
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-01 23:48

I created the component NotFound and it works fine when I go to a page that doesn\'t exist. But the same page it\'s appearing in all my pages, not only the one

4条回答
  •  -上瘾入骨i
    2021-01-02 00:02

    Simply import Switch from react-router-dom and wrap all your Routes in the Switch Component. Also Important here is to note to keep your 404Page component at the very bottom(just before your switch ending tag) This way it will match each component with its route first. If it matches, it will render the component or else check the next one. Ultimately if none matching routes will be founded, it will render 404Page

提交回复
热议问题