Lazy Loading and Iron:Router

I think I just found out something very interesting. My app is still using Iron:Router and I always thought for lazy loading I need to switch routers. I just tried the following and it seems to work

Router.route("/account/profile", {
  async onBeforeAction(){
    import '/imports/client/account_profile.js';
    this.next();
  },
  template: "accountProfile",
  name: "accountProfile",
  loginRequired: true,
  title: 'Account Profile',
});

Can someone confirm why this should/shouldn’t work?

It works because it’s a language feature (async/await), not a library feature.

4 Likes