1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Forward state with navigateByUrl in Angular

Discussão em 'Angular' iniciado por Maximilian von Unwerth, Junho 2, 2025.

  1. i want to pass some data, when changing the view with navigateByUrl like

    this.router.navigateByUrl(url, {state: {hello: "world"}});


    In the next view i want to simply log the hello attribute like

    constructor(public router: Router) { }

    ngOnInit(): void {
    console.log(this.router.getCurrentNavigation().extras.state.hello)
    }


    When I now do it this way, i get an error:

    ERROR TypeError: Cannot read property 'extras' of null
    at ProfileContactViewComponent.ngOnInit


    Am i doing this correctly or is there a better way to pass the data between the views? Thanks for your help.

    Continue reading...

Compartilhe esta Página