rdkcentral / Lightning-SDK

SDK for Lightning framework
Apache License 2.0
130 stars 69 forks source link

Overriding _handleBack in Router.App component #409

Open jhomlala opened 11 months ago

jhomlala commented 11 months ago

Hi, I've found interesting issue. _handleBack is not getting called in component which extends Router.App.

export class App extends Router.App {
  static _template() {
    ...
  }

  _setup() {
    startRotuer(routes)
  }

  _handleBack() {
    //This will be never called
  }
}

I've looked into router code and I've found that this is caused by this line: https://github.com/rdkcentral/Lightning-SDK/blob/8a841d7b525503c9ba1d6212470727943710d420/src/Router/utils/router.js#L167

Is this expected that router will override _handleBack? Shouldn't the app be able to decide whether it wants to navigate back or not?

In order to handle back navigation in our app component we had to fix it like this:

export class App extends Router.App {
  static _template() {
    ...
  }

  _setup() {
    startRotuer(routes)
    app._handleBack = function () {
      // Handle back here. Decide whether we should step back in navigation (pop) or do something else.
    }
  }

  _handleBack() {
    //This will be never called
  }
}

Thanks for your help!

sandeep-vedam commented 11 months ago

Hey @jhomlala

Thanks for your observation. The idea is that, when using the router, you intend for it to seamlessly manage and control this specific kind of behavior.

@erikhaandrikman, please confirm on this.

jhomlala commented 11 months ago

@sandeep-vedam Thanks for your answer. Still, it will be great if developers would have a possibility to enable this or not. Right now we can't change this behavior and we need to override once again _handleBack variable.

Also it would be useful if Router documentation will have this scenario explained. I couldn't find anything related to this behavior in docs page.