Atrisināts: reaģēt iegūt pašreizējo maršrutu

Galvenā problēma ar reaģēt, iegūstot pašreizējo maršrutu, ir tā, ka tas var būt lēns.

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

nosaukums

uselocation() āķis

Āķis uselocation() tiek izmantots, lai noteiktu, vai komponents ir jāatveido saknē vai nē. Ja komponents nav jāatveido saknē, tas var izmantot šo āķi, lai noteiktu, kur tā vietā tas ir renderēts.

Kā iegūt maršrutus

Ir daži veidi, kā iegūt maršrutus programmā React. Viens veids ir izmantot react-router. Vēl viens veids ir izmantot react-router-dom.

Related posts:

Leave a Comment