1

I am using React Router Dom version 5.2.0. The website URL has been successfully changed but the page is not automatically refreshed.

Following is my code:

import React from "react";
import "./home.scss";
import { BlogItem, Button, Gap } from "../../components";
import { useHistory } from "react-router-dom";

const Home = () => {
  const history = useHistory();

  return (
    <div className="home-page-wrapper">
      <div className="create-wrapper">
        <Button
          tittle="create blog"
          onClick={() => history.push("/create-blog")}
        />
      </div>
      <Gap height={20} />
      <div className="content-wrapper">
        <BlogItem />
        <BlogItem />
        <BlogItem />
        <BlogItem />
      </div>
      <div className="pagination">
        <Button tittle="Previous" />
        <Gap width={20} />
        <Button tittle="Next" />
      </div>
      <Gap height={20} />
    </div>
  );
};

export default Home;

I hope the website can move pages according to its function, and the website can refresh automatically when the url is changed.

  • ***Don't*** remove the `React.StrictMode` component. Bump to `react-router-dom@5.3.3` or higher to use a version that works with React 18 and the `React.StrictMode` component. See the linked duplicate for details. – Drew Reese Apr 20 '23 at 15:39

1 Answers1

-1

you need to use useNavigate instead

boryssssss
  • 39
  • 3