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

161
Visualizações
matching pathname in custom router

I am creating a custom router where i want to match the pathname to a specific web component.

public Router = new Router([
    new Route('/dev/', 'my-element'),
    new Route('/dev/other', 'other-view')
  ], "#application_page");

There could be other page names like /dev/page/1 so I need to ensure that it as solid as possible

My first approach is way too basic:

const pathname = window.location.pathname;
console.log(pathname);
for (let i = 0; i < this.routes.length; i++) {
  if (pathname.indexOf(this.routes[i].url) >= 0) {
    console.log(this.routes[i].url);

    const el = renderRoot.querySelector(this.containerId);
    if (el != null) {
      el.appendChild(this.routes[i].component);
      return;
    }
  }
}

What is the best way to find the correct route?

about 4 years ago · Juan Pablo Isaza
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