Rozwiązany: reaguj, pobierz aktualną trasę

Głównym problemem związanym z reagowaniem na pobieranie bieżącej trasy jest to, że może to być powolne.

There is no built-in way to get the current route in React. However, you can use the router's context to get the current location, which will give you the current pathname.

const { location } = this.context.router; console.log(location.pathname); // /some/path

Nazwa

uselocation() hak

Hak uselocation() służy do określenia, czy komponent powinien być renderowany w katalogu głównym, czy nie. Jeśli komponent nie powinien być renderowany w katalogu głównym, może użyć tego haka, aby określić, gdzie powinien być renderowany.

Jak uzyskać trasy

Istnieje kilka sposobów uzyskiwania tras w React. Jednym ze sposobów jest użycie routera reagowania. Innym sposobem jest użycie react-router-dom.

Powiązane posty:

Zostaw komentarz