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

437
Visualizações
path url split() find() angular

I have urls and I want to recover the beginning of the path but I don't know how to do it and being a beginner according to my research I should use the split() and find() method.

Here are the urls:

/test/someurls

/angular/someurls

I need to get /test and /angular is it possible to do that?

Thanks in advance.

ngOnInit() {

 let firstUrl: string = '/test/someurls';
 let secondUrl:string = '/angular/someurls';

 let t = firstUrl.split(" ").find(element =>element.startWith('/test');
    console.log(t);
}
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Here is code using split function.

function getBeginning(a) {
  return "/" + a.split("/")[1];
}
console.log(getBeginning("/test/some"));
console.log(getBeginning("/angular/some"));
about 4 years ago · Juan Pablo Isaza Relatório

0

Another interesting way with Angular api:

const urlTree = this.router.parseUrl('/angular/someurls');


...
getBeginningFromUrlTree(urlTree: UrlTree): string {
  return `/${urlTree.root.children.primary.segments[0].path}`;
}
about 4 years ago · Juan Pablo Isaza Relatório

0


crumbs = this.router.url.split('/');

constructor(private router: Router) {}

Something like this ?

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