Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda