Skip to content

Latest commit

 

History

History
51 lines (41 loc) · 945 Bytes

README.md

File metadata and controls

51 lines (41 loc) · 945 Bytes

Angular2-navigate-with-data

Angular2+/4/5 - navigate with data

Install

npm install angular2-navigate-with-data -save

How to use

Initialize into app.module.ts

  import "angular2-navigate-with-data";

Example

import {Router} from '@angular/router';

class PageOne {
    constructor (
        private router: Router
    ){}
    
    public redirect()
    {
        this.router.navigateByData({
            url: ["/PageTwo"],
            data: [1,2,3,4,5], //data - <any> type
            //extras: {} - <NavigationExtras> type, optional parameter
        });
    }
}
import {Router} from '@angular/router';
import {OnInit} from "@angular/core";

class PageTwo implements OnInit {
    constructor (
        private router: Router
    ){}
    
    public ngOnInit()
    {
    	console.log(this.router.getNavigatedData()); //output [1,2,3,4,5]
    }
}