rdkcentral / Lightning-SDK

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

'*' and '!' special routes is not working in SDK-v4.3.0 Router #221

Closed anton-epam closed 3 years ago

anton-epam commented 3 years ago

Hi.

I start migration of our app from 3.2.1 to 4.3.0 SDK version, and faced with a fact that special routes is not triggered at all. Here is an example:

routes = {
  boot: () => {
    return Promise.resolve()
  },
  bootComponent: SplashScreen,
  root: 'home',
  routes: [
    {
      path: 'home',
      component: HomeScreen
    },
    {
      path: '*',
      component: ErrorScreen,
      on: function (page, params) {
        Router.navigate(Screens.HOME)
        return Promise.reject(false)
      }
    },
   {
      path: '!',
      component: ErrorScreen,
      on: function (page, params) {
        Router.navigate(Screens.HOME)
        return Promise.reject(false)
      }
    }
  ]
}

If I will try to navigate to 'hom', 'sdfsfesefsef', or any other undefined url - I will always get bootComponent and '*' or '!' will not be triggrered. I had debugged Router code and find that issue happens inside 'getRouteByHash' function:

image

at some point (line 129 in route.js) matches array contains link to '$' (boot component) instead of url that we are trying to navigate. this leads to a fact that 'getRouteByHash' function returns Boot-component Router in 'handleHashChange' function - what in fact blocking underline code from execution of '*' route. As for '!' I had not checked, but seems the issue reason will be similar

Could you please fix that? I really could avoid this with handling navigation in 'beforeEachRoute' hook, but really - this is declared feature of Lightning SDK, and it should work properly

erikhaandrikman commented 3 years ago

Thanks for reporting this bug, there is a fix available in the feature branch: https://github.com/rdkcentral/Lightning-SDK/commit/e7395254cc5290a7fedfbd1b79d188804788bf17 this will check if there is a route available for the provided hash before navigating to the bootPage and navigate to the special * route

We're now testing this fix and will update this ticket the moment it's merged in master.

erikhaandrikman commented 3 years ago

Fixed in v4.4.0