D
D
Dyadko_Orest2020-05-23 13:47:16
JavaScript
Dyadko_Orest, 2020-05-23 13:47:16

How to fix error after page refresh (react-douter-dom)?

I'm trying to make routes using react-router-dom and ran into a problem that if I give a double path (/list/:name) then everything loads when I go, but if I refresh the page I get an error (there is a screenshot of the error below). If I give just (/: name) everything works well. What could be the problem?

Routes

<Switch>
        <Route exact path="/list/:name" children={<ChooseListFilm />} />
    </Switch>


header

<ul>
        <li>
          <Link to="/list/popular">Popular</Link>
        </li>
        <li>
          <Link to="/list/top_rated">Top rated</Link>
        </li>
        <li>
          <Link to="/list/upcoming">Upcoming</Link>
        </li>


ChooseListFilm
export default function ChooseListFilm() {
    let {name} = useParams();
  return (
        <ListFilms  
          filmType={name}
        />
  );
}


ListFilm

//Here I get the list of movies by API and display them

Screenshot of the error5ec8ff23df941443540804.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
myxomor469, 2020-05-23
@myxomor469

There you need to configure routes on the backend, since react's routes only work when the file with the application is loaded, and it is loaded at the root address.
You can interrupt the reboot on this page and make the update mechanism through the functions of the components

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question