Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!