Our project is using typescript. We have implemented an environment switcher in our project, and when the environment is switched, we navigate back to the splash screen to handle all of the initialization for the app so that it loads fresh with the new environment. However, when using Router.navigate('$') it throws a TypeError saying that the route hash is undefined. However, the app still works and behaves as intended. When debugging the issue and following data, it is fetching the correct route hash, #$, but for some reason it is sill throwing this error.
I was wondering if this is happening because we are navigation to the splash screen, and if so, what is the best way to route back to that screen? Or, if this is a result of lightning not being fully typed out for typescript? Or something else.
If I were doing this I would probably store the environment (and other settings) in local storage then call location.reload() to restart the app. I’m not sure what Lightning is doing between launch and calling the boot page so this seems like the safest/cleanest way.
TypeError generally refers to a JavaScript runtime exception and is often misunderstood as a TypeScript compiler error because of its name. That being said, I tried replicating this in a sample project and was unable to get it to produce a TypeError when calling Router.navigate('$'). It seems if you define a Boot Page route with path ‘$’ then that statement will navigate you to the boot page. If you can provide a link to a repo with a reproduction of that exact error I can look into it further.
But I’ll echo @lewispeel’s advice, I’m not sure relying on logic that is designed specifically for the first booting of an app is the best path for what you’re trying to accomplish. You’re not guaranteed to get a fresh app state in regards to the Lightning SDK router that way. Using local storage and a complete page refresh is likely a better idea unless there is a specific reason that cannot be done.