Keep navParams on livereload for dev environment


Hi folks,

I was wondering what would be the best approach to keep navParams for the page/component that we work on during development. We’re already using IonicPage() deeplinking so I can already land on the required page on refresh, however once page is refreshed on watch trigger, params/state disappear and you should navigate from the beginning or land in a deadloop.

I created following component for keeping the navParams as is for the active page and it does the job if only it’s injected to the component template. I would like to inject this component for all/current component templates when we’re on dev environment and push this responsibility to build system somehow. I don’t want it to be part of source code of each component’s template.

import { Component, OnDestroy } from '@angular/core';
import { StorageService } from '../storage/storage.service';
import { Environment } from '../../../apps/imech/src/env/environment';
import { NavController, NavParams } from 'ionic-angular';
import isEqual from 'lodash-es/isEqual';

    selector: 'kl-persistent-nav-params',
    providers: [StorageService],
    template: '',
export class PersistentNavParamsComponent implements OnDestroy {

    constructor(public navParams: NavParams,
                public navController: NavController,
                public storageService: StorageService) {

        if ( === 'dev') {
            const params = this.getNavParams();
            if (params && !isEqual(params, && !Object.keys( {
       = params;

    public ngOnDestroy() {

    private subscribeToViewEvents() {
        this.navController.viewDidEnter.subscribe(() => {

        this.navController.viewWillLeave.subscribe(() => {

    private get storageKey() {
        return 'navParams';

    private getNavParams() {
        const navData = this.storageService.getObject(this.storageKey);
        if (navData) {
            return navData;
        return undefined;

    private setNavParams() {

Any ideas on how to solve my issue or providing a better approach for this goal?

Thanks in advance!