Skip to content

'history.state' object is getting lost when navigate using back/forward buttons #28108

@alecvolo

Description

@alecvolo

🐞 bug report

Affected Package

The issue is caused by package @angular/router....

Is this a regression?

No

Description

I think there is a small bug - the `history.state` object is getting lost when navigate using back/forward buttons.

The fix should be pretty simple- set the restored state into the NavigationExtras parameter in the call of scheduleNavigation in Router.setUpLocationChangeListener() method :

        // Navigations coming from Angular router have a navigationId state property. When this
        // exists, restore the state.
        const state = change.state && change.state.navigationId ? change.state : null;
     setTimeout(
            () => { this.scheduleNavigation(rawUrlTree, source, state, {replaceUrl: true, state }); }, 0);

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-bupuzn created by @fjauer - just use back/forward after pressing Test button

🔥 Exception or Error





🌍 Your Environment

Angular Version:


Angular CLI: 7.2.1
Node: 10.15.0
OS: win32 x64
Angular: 7.2.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.12.1
@angular-devkit/build-angular     0.12.1
@angular-devkit/build-optimizer   0.12.1
@angular-devkit/build-webpack     0.12.1
@angular-devkit/core              7.2.1
@angular-devkit/schematics        7.2.1
@angular/cdk                      7.2.1
@angular/cli                      7.2.1
@angular/flex-layout              7.0.0-beta.23
@angular/material                 7.2.1
@ngtools/webpack                  7.2.1
@schematics/angular               7.2.1
@schematics/update                0.12.1
rxjs                              6.0.0
typescript                        3.2.2
webpack                           4.23.1

Anything else relevant?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions