Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the purpose of passing data:{} to a route?

The Angular Material Doc Site passes {} to the Homepage route:

  {path: '', component: HomePage, pathMatch: 'full', data: {}}

Just curious what the purpose of data: {} is?

Update

After examining this closer I think that they do it so that they don't have to perform a null check using the Elvis operator in their templates.

In other words they don't have to do data?.property.

like image 592
Ole Avatar asked Oct 17 '25 06:10

Ole


1 Answers

Only thing I can think of is that {} != null which means that you can determine the difference between whether this has been intentionally set to nothing ({}) or if a dev has forgotten to set the data for the route which would result in it being null (or undefined) I would need to check...

like image 184
Zze Avatar answered Oct 18 '25 21:10

Zze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!