I need to access component when click link but not change URL ?

28 views
Skip to first unread message

ahmed elbarbary

unread,
Dec 20, 2019, 8:37:45 PM12/20/19
to Angular and AngularJS discussion

I work on web app done by angular 7 


I need when click on any item on list on have router link on nvabar.component.html   go to specified component on router link


without change URL .


navbar.component.html


<div id="z2-2cols-leftpanel">
       
<ul class="z2-leftpanel-ullinks">
         
<li>
           
<a routerLink="/overview" class="active z2tabBtn" data-z2tab="overview_content">
             
<div class="z2iconfont icon-Basic-Info"></div>
             
<div class="ulllinks-text">Overview</div>
           
</a>
         
</li>
         
<li>
           
<a routerLink="/family" class="z2tabBtn" data-z2tab="family_content">
             
<div class="z2iconfont icon-Cross-Reference"></div>
             
<div class="ulllinks-text">Family</div>
           
</a>
         
</li>
         
<li>
</ul>
</div>



in app-routing.module.ts

{ path: 'overview', component: OverviewComponent },
{ path: 'family', component: FamilyComponent }


on overview.component.ts



import { CompanyService } from './../../service/company.service';
import { Component, OnInit } from '@angular/core';
import { PartDetailsService } from 'src/app/service/part-details.service';
 




@Component({
  selector
: 'app-overview',
  templateUrl
: './overview.component.html',
  styleUrls
: ['./overview.component.css']
})
export class OverviewComponent implements OnInit {


 
 
public companyProfile;
  constructor
(public partDetailsService: PartDetailsService
   
,         public companyService: CompanyService) {
   
   
}


  ngOnInit
() {
console
.log("welcome overview component ");
 
}


so I need when click on link overview on navbar.component.html 


go to component overview and show welcome on console without change URL 


so 


How to do that please ?


current status is when click on link overview exist on navbar it go to overview component 


but it change URL


what i need is when click overview link go to component overview but not change URL ?


Example


suppose i have  URL localhost:4200/family


when click overview component go to overview component but not change URL to localhost:4200/overview meaning 


link localhost:4200/family will be in URL although i click overview component and show message on console welcome overview 


Olaleye Israel

unread,
Dec 21, 2019, 5:01:08 AM12/21/19
to ang...@googlegroups.com
you cannot navigate to another route without changing the URL... you can only screw with the history by reading about navigationextras from the doc...
skipLocationChangeboolean

Navigates without pushing a new state into history.

// Navigate silently to /view
this.router.navigate(['/view'], { skipLocationChange: true });
replaceUrlboolean

Navigates while replacing the current state in history.

// Navigate to /view
this.router.navigate(['/view'], { replaceUrl: true });


--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular/15659218-a57f-4186-960a-fd90f1eaaa70%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages