Skip to content

Subscribing to route params is not working #16581

@ildar-icoosoft

Description

@ildar-icoosoft

Bug Report

Ionic Info
Run ionic info from a terminal/cmd prompt and paste the output below.

Ionic:

   ionic (Ionic CLI)             : 4.3.0 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.0.0-beta.12
   @angular-devkit/build-angular : 0.7.5
   @angular-devkit/schematics    : 0.7.5
   @angular/cli                  : 6.1.5
   @ionic/angular-toolkit        : 1.1.0

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : none
   Cordova Plugins       : no whitelisted plugins (0 plugins total)

System:

   Android SDK Tools : 26.1.1 (/Users/ildar/Library/Android/sdk)
   ios-deploy        : 1.9.2
   NodeJS            : v11.0.0 (/usr/local/bin/node)
   npm               : 6.4.1
   OS                : macOS High Sierra
   Xcode             : Xcode 9.4 Build version 9F1027a


Describe the Bug
Subscribing to route params is not working.
I have a page "/news" with parameter: page (for example /news;page=1)

I don't want to reinitialize news page when page is changed. I just want to subscribe to page changes, I've tried this code:

this.route.params.subscribe(params => ...)

If I open /news page and navigate to /news page with different page parameter:

this.router.navigate(['/news', {page: 3} ])

then NewsPage component is reinitialized (component is destroyed and created). But if I use queryParams (/news?page=2) instead of params (/news;page=2) then everything works fine:

this.route.queryParams.subscribe(params => {
    ...
});

If I call

this.router.navigate(['/news'], {queryParams: {page: 2}} ) 

then the page is NOT reinitilized. Just subscribe callback is executed. Why does it happen?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions