Search code examples
angularjstypescriptangular-router

How to pass a variable in a URL


I want to pass the projectId along with the url. How can I achieve that?

    var projectId = e.data.id;
    var url = `/pages/project_details/,`projectId`,/Ongoing`;
    this.router.navigateByUrl(url).then(e =>{
      if(e){
        console.log('routed');
      }else{
        console.log('not routed');
      }
    });

Solution

  • If You are using Angular 7 or up version than you can use following standard of typescript

    const projectId = e.data.id;;
    const url = '/pages/project_details/' + projectId + '/Ongoing'; 
    console.log(url )