@angular/router#NavigationEnd TypeScript Examples
The following examples show how to use
@angular/router#NavigationEnd.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: auth.gourd.ts From nuxx with GNU Affero General Public License v3.0 | 6 votes |
constructor(
private router: Router,
private authenticationService: AuthenticationService
) {
this.router.events
.pipe(filter(event => event instanceof NavigationEnd))
.subscribe(({ urlAfterRedirects }: NavigationEnd) => {
!this.mapAuthUrls[location.pathname] ? localStorage.setItem('lastPageBeforeRegistrationOrLogin', location.pathname) : ''
});
}
Example #2
Source File: tour-service.service.ts From loopback4-microservice-catalog with MIT License | 6 votes |
private navigateAndMoveToNextStep(
currentStep: TourStep,
tourInstance: Tour,
tourState: TourState,
index: number,
) {
if (index < tourInstance.tourSteps.length - 1) {
this.router.navigate([currentStep.nextRoute]);
this.router.events.subscribe((event: NavigationEvent) => {
const nextStep = tourInstance.tourSteps.filter(
ts => ts.id === currentStep.nextStepId,
)[0];
if (
event instanceof NavigationEnd &&
event.url === nextStep.currentRoute
) {
this.moveToNextStep(tourInstance, tourState, currentStep, index);
}
});
} else {
this.moveToNextStep(tourInstance, tourState, currentStep, index);
}
}
Example #3
Source File: app.component.ts From nestjs-angular-starter with MIT License | 6 votes |
navigationInterceptor(event: RouterEvent): void {
if (event instanceof NavigationStart) {
this.isLoading = true;
// Toogle navbar collapse when clicking on link
const navbarCollapse = $('.navbar-collapse');
if (navbarCollapse != null) {
navbarCollapse.collapse('hide');
}
}
if (event instanceof NavigationEnd) {
this.isLoading = false;
}
// Set loading state to false in both of the below events to hide the spinner in case a request fails
if (event instanceof NavigationCancel) {
this.isLoading = false;
}
if (event instanceof NavigationError) {
this.isLoading = false;
}
}
Example #4
Source File: app.component.ts From youpez-admin with MIT License | 6 votes |
ngOnInit(): void {
this.route.queryParams
.subscribe((queryParams) => {
if (queryParams.theme) {
this.settingsService.setTheme(queryParams.theme)
}
else {
this.settingsService.setTheme(getSessionStorage('--app-theme'))
}
if (queryParams.sidebar) {
this.settingsService.setSideBar(queryParams.sidebar)
}
else {
this.settingsService.setSideBar(getSessionStorage('--app-theme-sidebar'))
}
if (queryParams.header) {
this.settingsService.setHeader(queryParams.header)
}
else {
this.settingsService.setHeader(getSessionStorage('--app-theme-header'))
}
})
this.router.events.subscribe((event) => {
if (event instanceof NavigationStart) {
}
if (event instanceof NavigationEnd) {
if (!this.appLoaded) {
(<any>window).appBootstrap()
this.appLoaded = true
}
}
if (event instanceof NavigationCancel) {
}
})
}
Example #5
Source File: google-analytics.effects.ts From enterprise-ng-2020-workshop with MIT License | 6 votes |
pageView = createEffect(
() => () =>
this.router.events.pipe(
filter((event) => event instanceof NavigationEnd),
tap((event: NavigationEnd) => {
(<any>window).ga('set', 'page', event.urlAfterRedirects);
(<any>window).ga('send', 'pageview');
})
),
{ dispatch: false }
);
Example #6
Source File: main.component.ts From digital-bank-ui with Mozilla Public License 2.0 | 6 votes |
ngOnInit(): void {
this.routerEventSubscription = this.router.events
.pipe(
filter(event => event instanceof NavigationEnd),
map(() => this.getTitle(this.router.routerState, this.router.routerState.root).join(' - ')),
)
.subscribe(title => this.titleService.setTitle(title));
this.tenant$ = this.store.select(fromRoot.getTenant);
this.username$ = this.store.select(fromRoot.getUsername);
this.menuService.onItemClick().subscribe(event => {
this.onContecxtItemSelection(event.item.title);
});
}
Example #7
Source File: app.component.ts From open-genes-frontend with Mozilla Public License 2.0 | 6 votes |
private handleRouterState(): void {
this.router.events.pipe(takeUntil(this.subscription$)).subscribe((event: RouterEvent) => {
if (event instanceof NavigationEnd || event instanceof RouteConfigLoadEnd) {
// Hide progress spinner or progress bar
this.currentRoute = event.url;
if (this.currentRoute === '/404') {
this.isFooterVisible = false;
}
setTimeout(() => {
this.document.body.classList.remove('body--loading');
}, 2000);
}
});
}
Example #8
Source File: app.service.ts From onchat-web with Apache License 2.0 | 6 votes |
/**
* ę£ęµč·Æē±åƼčŖäŗ件
*/
detectNavigation() {
this.router.events.subscribe((event: Event) => {
switch (true) {
case event instanceof NavigationStart:
this.globalData.navigating = true;
break;
case event instanceof NavigationCancel:
this.feedbackService.slightVibrate(); // å¦ęč·Æē±čæåč¢«åę¶ļ¼å°±éåØäøäøļ¼č”Øē¤ŗé»ę¢
case event instanceof NavigationEnd:
case event instanceof NavigationError:
this.globalData.navigating = false;
break;
}
});
}
Example #9
Source File: tour-service.service.ts From loopback4-microservice-catalog with MIT License | 6 votes |
private navigateAndMoveToPrevStep(
currentStep: TourStep,
tourInstance: Tour,
tourState: TourState,
index: number,
removedSteps: TourStep[],
) {
let moveToLastRemovedStep = false;
if (index === 0 && removedSteps.length) {
moveToLastRemovedStep = true;
}
const prevRoute = moveToLastRemovedStep
? removedSteps[removedSteps.length - 1].prevRoute
: currentStep.prevRoute;
this.router.navigate([prevRoute]);
this.router.events.subscribe((event: NavigationEvent) => {
let prevStep: TourStep;
if (moveToLastRemovedStep) {
prevStep = removedSteps[removedSteps.length - 1];
} else {
prevStep = tourInstance.tourSteps.filter(
ts => ts.id === currentStep.prevStepId,
)[0];
}
if (
event instanceof NavigationEnd &&
event.url === prevStep.currentRoute
) {
this.moveToPrevStep(
tourInstance,
tourState,
currentStep,
index,
removedSteps,
);
}
});
}
Example #10
Source File: liquidity-providing.service.ts From rubic-app with GNU General Public License v3.0 | 6 votes |
public watchWhitelist(): Observable<boolean> {
return combineLatest([
this.walletConnectorService.addressChange$,
this.userAddress$,
this.router.events.pipe(filter(e => e instanceof NavigationEnd))
]).pipe(
switchMap(() =>
from(
this.web3PublicService[this.blockchain].callContractMethod<boolean>(
this.lpContractAddress,
LP_PROVIDING_CONTRACT_ABI,
'viewWhitelistInProgress'
)
)
),
tap(isWhitelistInProgress => {
const isWhitelistUser = this.checkIsWhitelistUser(this.userAddress);
const isOnDepositForm = this.router.url.includes('deposit');
this.zone.run(() => {
this._isWhitelistInProgress$.next(isWhitelistInProgress);
this._isWhitelistUser$.next(isWhitelistUser);
});
if (!isWhitelistUser && isWhitelistInProgress && isOnDepositForm) {
this.window.location.assign(this.window.location.origin + '/liquidity-providing');
}
if (isWhitelistUser && isWhitelistInProgress && isOnDepositForm) {
this.setDepositType(DepositType.WHITELIST);
}
}),
takeUntil(this._stopWhitelistWatch$)
);
}
Example #11
Source File: app.component.ts From ng-icons with MIT License | 6 votes |
ngOnInit(): void {
this.router.events.subscribe(event => {
if (event instanceof NavigationStart) {
this.loading$.next(true);
}
if (event instanceof NavigationEnd) {
this.loading$.next(false);
}
});
}
Example #12
Source File: data-source-list.component.ts From EDA with GNU Affero General Public License v3.0 | 6 votes |
constructor(public dataModelService: DataSourceService,
private alertService: AlertService,
private route: ActivatedRoute,
private spinnerService: SpinnerService,
private router: Router) {
this.navigationSubscription = this.router.events.subscribe(
(e: any) => {
if (e instanceof NavigationEnd) {
this.ngOnInit();
}
}, (err) => this.alertService.addError(err)
);
}
Example #13
Source File: top-progress-bar.component.ts From ng-ant-admin with MIT License | 6 votes |
constructor(private router: Router, private cdr: ChangeDetectorRef) {
this.router.events.subscribe(evt => {
// č”Øē¤ŗåØę°ę§å č½½ęäøŖč·Æē±é
ē½®å触åēäŗ件ć
if (!this.isFetching && evt instanceof RouteConfigLoadStart) {
this.isFetching = true;
this.cdr.markForCheck();
}
if (!this.isFetching && evt instanceof NavigationStart) {
this.isFetching = true;
this.cdr.markForCheck();
}
if (evt instanceof NavigationError || evt instanceof NavigationCancel) {
this.isFetching = false;
if (evt instanceof NavigationError) {
}
this.cdr.markForCheck();
return;
}
if (!(evt instanceof NavigationEnd || evt instanceof RouteConfigLoadEnd)) {
return;
}
if (this.isFetching) {
setTimeout(() => {
this.isFetching = false;
this.cdr.markForCheck();
}, 600);
}
});
}
Example #14
Source File: user-business.component.ts From nodejs-angular-typescript-boilerplate with Apache License 2.0 | 6 votes |
private loadParamsUrl(): void {
this.router.events.subscribe((event) => {
if (event instanceof NavigationEnd) {
this.route.params.subscribe((params) => {
if (this.userId !== params.userId) {
this.userId = params.userId;
this.loadUser(this.userId);
}
});
}
});
}
Example #15
Source File: nav.component.ts From WiLearning with GNU Affero General Public License v3.0 | 6 votes |
constructor(
public i18n: I18nService,
private breakpointObserver: BreakpointObserver,
private router: Router,
private logger: LoggerService,
) {
this.router.events.subscribe(value => {
if ( value instanceof NavigationEnd) {
this.redirectedUrl = value.urlAfterRedirects;
}
});
}
Example #16
Source File: environments.service.ts From data-annotator-for-machine-learning with Apache License 2.0 | 6 votes |
constructor(public router: Router) {
console.log('APP_CONFIGļ¼', this.configuration);
this.nodeEnvironment =
this.configuration === '' || this.configuration.startsWith('$')
? ''
: `.${this.configuration}`;
this.env = require('../../environments/environment' + this.nodeEnvironment);
console.log('Environment:', this.nodeEnvironment);
// Global site tag (gtag.js) - Google Analytics Start
if (this.configuration == 'prod' && this.env.environment.googleTrackId) {
this.router.events.subscribe((event) => {
if (event instanceof NavigationEnd) {
gtag('config', this.env.environment.googleTrackId, {
page_path: event.urlAfterRedirects,
});
}
});
}
}
Example #17
Source File: dropdown.directive.ts From matx-angular with MIT License | 6 votes |
public ngOnInit(): any {
this._router = this.router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe((event: NavigationEnd) => {
this.navlinks.forEach((link: DropdownLinkDirective) => {
if (link.group) {
const routeUrl = this.getUrl();
const currentUrl = routeUrl.split('/');
if (currentUrl.indexOf( link.group ) > 0) {
link.open = true;
this.closeOtherLinks(link);
}
}
});
});
}
Example #18
Source File: spinner.component.ts From flingo with MIT License | 6 votes |
constructor(private router: Router, @Inject(DOCUMENT) private document: Document) {
this.router.events.subscribe(
(event) => {
if (event instanceof NavigationStart) {
this.isSpinnerVisible = true;
} else if (
event instanceof NavigationEnd ||
event instanceof NavigationCancel ||
event instanceof NavigationError
) {
this.isSpinnerVisible = false;
}
},
() => {
this.isSpinnerVisible = false;
}
);
}
Example #19
Source File: app.component.ts From np-ui-lib with MIT License | 6 votes |
ngOnInit(): void {
this.router.events.subscribe((ev: any) => {
if (ev instanceof NavigationStart && !this.isMobileView) {
if (ev.url === "" || ev.url === "/" || ev.url === "/how-to-add") {
this.showMenu = false;
this.isHomePage = true;
} else {
this.showMenu = true;
this.isHomePage = false;
}
}
if (ev instanceof NavigationEnd) {
document.querySelector(".main-container").scrollTo(0, 0);
}
});
}
Example #20
Source File: app.component.ts From nodejs-angular-typescript-boilerplate with Apache License 2.0 | 6 votes |
ngAfterViewInit(): void {
this.router.events.subscribe((event) => {
if (
event instanceof NavigationEnd || event instanceof NavigationCancel
) {
this.loading = false;
}
});
}
Example #21
Source File: breadcrumb.component.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 6 votes |
constructor(
public router: Router,
public activatedRoute: ActivatedRoute,
public title: Title,
public sidenavMenuService: SidenavMenuService
) {
this.router.events
.pipe(filter(event => event instanceof NavigationEnd))
.pipe(map(() => this.activatedRoute))
.pipe(
map(route => {
while (route.firstChild) {
route = route.firstChild;
}
return route;
})
)
.pipe(filter(route => route.outlet === 'primary'))
.pipe(mergeMap(route => route.data))
.subscribe(event => {
// this.title.setTitle(event['title']);
this.pageInfo = event;
});
}
Example #22
Source File: tour-service.service.ts From loopback4-microservice-catalog with MIT License | 6 votes |
private navigateAndMoveToPrevStepRemoved(
currentStep: TourStep,
tourInstance: Tour,
tourState: TourState,
index: number,
removedSteps: TourStep[],
) {
this.router.navigate([currentStep.prevRoute]);
this.router.events.subscribe((event: NavigationEvent) => {
const prevStep = tourInstance.tourSteps.filter(
ts => ts.id === currentStep.prevStepId,
)[0];
if (
event instanceof NavigationEnd &&
event.url === prevStep.currentRoute
) {
this.moveToPrevStepRemoved(
tourInstance,
tourState,
currentStep,
index,
removedSteps,
);
}
});
}
Example #23
Source File: header.component.ts From barista with Apache License 2.0 | 6 votes |
constructor(
public router: Router,
public navService: NavService,
private authService: AuthService,
public appComponent: AppComponent,
) {
authService.statusChange.pipe(untilDestroyed(this)).subscribe((value: AuthServiceStatus) => {
this.message = value.statusMessage;
});
this.router.events.subscribe((routeData) => {
if (routeData instanceof NavigationEnd) {
var route = this.router.routerState.root;
while (route.firstChild) {
route = route.firstChild;
}
const adminRoute = route.snapshot.data['isAdminRoute'];
const path = routeData.urlAfterRedirects;
if (adminRoute) {
this.onHome = false;
this.onProj = false;
this.onAdmin = true;
} else if (path.startsWith('/home')) {
this.onHome = true;
this.onProj = false;
this.onAdmin = false;
} else if (path.startsWith('/project')) {
this.onHome = false;
this.onProj = true;
this.onAdmin = false;
} else {
this.onHome = false;
this.onProj = false;
this.onAdmin = false;
}
}
});
}
Example #24
Source File: dynamic-browser-title.service.ts From nghacks with MIT License | 6 votes |
private init(): void {
if (this._hasDynamicTitleServiceInitialized) {
throw new Error('DynamicTitleService already initialized! Initialize it only once at the application bootstrap.');
}
this._router.events
.pipe(
filter((event) => event instanceof NavigationEnd),
distinctUntilChanged()
)
.subscribe((route) => {
this.check();
});
this._hasDynamicTitleServiceInitialized = true;
}
Example #25
Source File: packages.component.ts From SideQuest with MIT License | 6 votes |
constructor(
public adbService: AdbClientService,
public appService: AppService,
public spinnerService: LoadingSpinnerService,
public statusService: StatusBarService,
private repoService: RepoService,
router: Router,
route: ActivatedRoute
) {
appService.webService.isWebviewOpen = false;
appService.resetTop();
appService.isPackagesOpen = true;
this.appService.setTitle('Installed Apps');
this.sub = router.events.subscribe(val => {
if (val instanceof NavigationEnd) {
this.routerPackage = route.snapshot.paramMap.get('packageName');
}
});
this.show_all = !!localStorage.getItem('packages_show_all');
}
Example #26
Source File: analytics.service.ts From ngx-admin-dotnet-starter with MIT License | 6 votes |
trackPageViews() {
if (this.enabled) {
this.router.events.pipe(
filter((event) => event instanceof NavigationEnd),
)
.subscribe(() => {
ga('send', {hitType: 'pageview', page: this.location.path()});
});
}
}
Example #27
Source File: shell.service.ts From scion-microfrontend-platform with Eclipse Public License 2.0 | 6 votes |
public isDetailsOutletActive$(): Observable<boolean> {
return this._router.events
.pipe(
filter(event => event instanceof NavigationEnd),
map((event: NavigationEnd) => {
const urlTree = this._router.parseUrl(event.urlAfterRedirects);
return urlTree.root.children[PRIMARY_OUTLET]?.children['details'] !== undefined;
}),
);
}
Example #28
Source File: explorer-ui.component.ts From thorchain-explorer-singlechain with MIT License | 6 votes |
constructor(
private activatedRoute: ActivatedRoute,
private router: Router,
private api: ApiService
) {
const sub = this.router.events
.pipe(filter((ev) => ev instanceof NavigationEnd))
.subscribe((ev) => {
if (!this.paramMap[this.router.url]) {
this.paramMap[this.router.url] = {};
}
if (!this.pathMap[this.router.url]) {
this.pathMap[this.router.url] = {};
}
this.updateEndpoint(this.router.url);
// this.updateParamFromUrl(this.router.url);
});
this.subs.push(sub);
}
Example #29
Source File: title.service.ts From blockcore-hub with MIT License | 6 votes |
initialize() {
this.router.events.pipe(
filter(event => event instanceof NavigationEnd),
map(() => this.router.routerState.root),
map(route => {
while (route.firstChild) {
route = route.firstChild;
}
return route;
}),
filter(route => route.outlet === 'primary'),
mergeMap(route => route.data),
// eslint-disable-next-line @typescript-eslint/dot-notation
map(data => ({ title: data['title'], prefix: data['prefix'] })),
).subscribe(title => {
let formattedTitle = title.title != null ? title.title : '';
if (title.prefix != null) {
formattedTitle = title.prefix + ' - ' + formattedTitle;
}
// For the document title, we'll append the app title.
// if (this.appTitle != null) {
// this.document.title = formattedTitle + ' - ' + this.appTitle;
this.document.title = this.setup.name + ' - ' + formattedTitle;
// }
this.title.next(formattedTitle);
});
}