Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

85
Visualizações
How to get the last part of the current URL with react router v6?

How can I get the last part of the current url with react router v6?

For example:

If the current path is https://localhost:4200/example/example-details, then I want to check it like this

const location = useLocation();

if (location.pathname === '/example-details')) {
  // do some stuff here
}

..but this always returns the full path.

It works with location.pathname.includes('/example-details'), but I'm curious if there is a way with the react router, like it is possible with the Angular router..

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

check for

location.pathname.includes('/example-details')
about 4 years ago · Juan Pablo Isaza Relatório

0

const location = useLocation();
const [pathName, setPathName] = useState(null) ;

useEffect(() => {
    if(location) {
        let tmp = location.pathName.slice(location.pathName.lastIndexOf("/") , location.pathName.length) ;
        setPathName(tmp) ;
    }
}, [location])
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda