question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ActivatedRoute is not updated correctly when using ion-router-outlet

See original GitHub issue

Bug Report

Ionic version: 4.0.0-rc.0

Current behavior: Getting correct activated route using Angular ActivatedRoute service only works the first time when “ion-router-outlet” is used and router NavigationEnd event occurs.

Expected behavior: Getting correct activated route using Angular ActivatedRoute service works every time NavigationEnd event occurs and “ion-router-outlet” is used.

Steps to reproduce: Try to get activated route every time Angular router fires NavigationEnd event.

Related code: Following code correctly returns data object of the activated route when Angular “router-outlet” is used but only works the first time when Ionic “ion-router-outlet” is used:

import {Component, OnInit} from '@angular/core';
import {ActivatedRoute, NavigationEnd, Router} from '@angular/router';
import {filter, map, mergeMap} from 'rxjs/operators';

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

    constructor(
        private router: Router,
        private activatedRoute: ActivatedRoute
    ) {}

    ngOnInit() {
        this.router.events
            .pipe(
                filter((event) => event instanceof NavigationEnd),
                map(() => this.activatedRoute),
                map((route) => {
                    while (route.firstChild) {
                        route = route.firstChild;
                    }
                    return route;
                }),
                mergeMap((route) => route.data)
            )
            .subscribe(
                (routeData) => {
                    console.log(routeData);
                }
            );
    }

}

Other information: daem0ndev explains the issue quite well in this comment. This issue is quite important and it should be blocker for stable version 4 release.

As a workaround “IonicRouteStrategy” can be removed from app module providers until the issue is fixed.

Related issues: ActivatedRoute.queryParams break after navigation StackController Page reuse uses old Page data

Ionic info:

Ionic:

   ionic (Ionic CLI)             : 4.6.0
   Ionic Framework               : @ionic/angular 4.0.0-rc.0
   @angular-devkit/build-angular : 0.11.4
   @angular-devkit/schematics    : 7.1.4
   @angular/cli                  : 7.1.4
   @ionic/angular-toolkit        : 1.2.2

System:

   NodeJS : v10.1.0 (C:\Program Files\nodejs\node.exe)
   npm    : 6.5.0
   OS     : Windows 10

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
nathan-torquatocommented, Mar 19, 2019

Same thing here, @abierbaum . In our case, disabling { provide: RouteReuseStrategy, useClass: IonicRouteStrategy } did the trick, but I think the problem deserves some deep investigation.

2reactions
mhartingtoncommented, Mar 29, 2019

Hey everyone. We just merged in #17888 which fixes this. Thanks for all your patience here 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

ActivatedRoute is not updated correctly when using ion-router ...
Getting correct activated route using Angular ActivatedRoute service works every time NavigationEnd event occurs and "ion-router-outlet" is used ...
Read more >
ionic4 Angular 7 query params subscribe is not triggering on ...
This is my code import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Params, Router } from '@angular/router'; ...
Read more >
Angular Navigation: How Routing & Redirects Work in Angular ...
This guide covers how routing works in an app built with Ionic and Angular. ... uses of non-linear routing is with tabs and...
Read more >
RouterOutlet - Angular
Using named outlets and secondary routes, you can target multiple outlets in the same RouterLink directive. The router keeps track of separate branches...
Read more >
Accessing Route Parameters with ActivatedRoute vs ...
This means it changed from the starting value to the new value. Now let's extract the value using ActivatedRouteSnapshot . Extract a Parameter ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found