1
votes

I have been attempting to follow along with the optional route parameters section of the angular documentation, in order to add and operate with optional parameters on some routes in my own application.

However, there is clearly something I am missing or not understanding, as I cannot get this to work.

The expected behaviour: when clicking the router links the text changes to show the optional parameter.

Actual behaviour: the parameter value is never defined.

I have created a stackblitz forked from a template and reproduced the problem as simply as I can.

https://stackblitz.com/edit/angular-7-master-9c4dwm

1

1 Answers

1
votes

You can extract your parameter after subscribing to the paramMap as below:

this.route.paramMap.subscribe((parameters: any) => {
  this.parameter = parameters.params.parameter;
});

See the updated plunk.