IRouter vs Router

import { inject, Router, IRouter } from 'aurelia'

@inject( Router, IRouter)

export class Component {
    constructor(router, irouter) {
        ....
    }

   onBtnPress() {
      this.router.load(...)
      this.irouter.load(...)
   }
}

this.router throws an error that the route/component was not found/registered.

this.irouter works as expected.

Whats the difference between the two? Using the inspector, both seem to have the same properties.

1 Like

They are not different because they resolve to the same instance. The interface is there to encourage refrainment from poking any concrete/internal implementation, and thus avoid deep coupling to the underlying framework overtime.

It also allows framework authors, in this case, the Aurelia team, to simplify the public contract of the classes/interfaces committed so that there’ more room for refactoring & improvement.

1 Like

That’s great. Thank you.

1 Like