0

I'm trying to import this example in my Application: https://stackblitz.com/edit/angular-breadcrumb-router

But in the file breadcrumb.component.ts the Visual Studio Code says

Object is possibly 'undefined'.ts(2532)

for this line:

const label = route.routeConfig ? route.routeConfig.data['breadcrumb'] : 'Home';

So I can't use it and I don't understand why.

jonrsharpe
  • 99,167
  • 19
  • 183
  • 334
  • 2 question...did you set up your routes correctly from the example, and if so, have you tried console logging what's in route.routeConfig.data? – tcrite Mar 18 '21 at 12:41

1 Answers1

0

Use the Optional Chaining ?. operator:

const label = route?.routeConfig?.data['breadcrumb'] ?? 'Home';

Take a look at How can I solve the error 'TS2532: Object is possibly 'undefined'?

I guess you use a newer version of Typescript or somehow activated that rule.