Description
The problem
We have an app shell architecture, meaning a host app that loads several other apps on our page. This lets us maintain and deploy each app separately. The app shell routes to /app1
and App 1 will route to everything after /app1/...
. Some of the loaded apps are using Navigation.program
. When the path changes from /app1
to /app2
, App 1 still listens to popstate events even though it should be idle.
Possible workarounds
There are a couple of ways to circumvent this from being a problem.
-
Removing all subscriptions. => Won't work. There is no way to tell the
Navigation.program
to stop listening to this event since the subscription is untouchable and always there https://github.com/elm-lang/navigation/blob/master/src/Navigation.elm#L73. -
"Turning off" the App1 when routing away (with something like this
update = (\model msg -> if model.isMounted then update model msg else (model, Cmd.none))
) => would work but bloats the model and update function a little bit. -
Making sure each app only parses routes that are within it's namespace (only parse stuff starting with
/app1
)
All these methods will just elimate the reaction to the event, rather than removing the actual event listener.