single-spa-layout icon indicating copy to clipboard operation
single-spa-layout copied to clipboard

How to display an application inside default layout without recalculating if route matched in activeWhen function

Open apostrophedottilde opened this issue 3 years ago • 1 comments

Great framework, thanks so much! I have some concerns or misunderstandings about how the default routes should be working and I'd much appreciate some education here . If I set a default route in either html markup or in JSON built programatically (my preference) where the child is just some markup as per the example in the docs, then if I enter an unmapped url into the url bar I get the markup defined in the default root displayed onto my page, nice!

<template id="single-spa-layout">
  <single-spa-router mode="history" base="/">
    <route default>
      <h1>404 what page were you expecting to see?</h1>
    </route>
  </single-spa-router>
</template>

However if I am to try to display my proper single-spa mf-page-not-found-error application instead....

<template id="single-spa-layout">
  <single-spa-router mode="history" base="/">
    <route default>
      <application name="@my-interesting-company/mf-page-not-found-error"></application>
    </route>
  </single-spa-router>
</template>

...then nothing is displayed when my URL entered matches no predefined route.

After a good bit of messing around I realised that it was because I would still need to configure the activeWhen() function that's passed into the registerApplication function to be able to know when to display that @my-interesting-company/mf-page-not-found-error application.

This to me feels like it goes against the purpose of a default root so I am hoping that I have just missed something in the documentation.

I would have thought that the default root registration should be a special case where no activeWhen() function is required as that could be driven by the knowledge of whether a URL matched or not.

As things are I am about to go down the avenue of trying to figure out what my routes might be (they are not known upfront as my app is built from config so it's non-trivial) and then writing some complex code in the activeWhen() to determine whether or not to render the route not found application.

Is there a more simple solution to this please? I guess there is a function in the framework somewhere that calculates a route match so even knowing how I can access that would help me a great deal.

Thanks for all your great work. In general this framework has allowed me to build a fairly complex dynamically built site so much more simple than it could have been :)

apostrophedottilde avatar Apr 20 '22 18:04 apostrophedottilde

Hi @apostrophedottilde, since the question is old, have you been able to resolve it?

MilanKovacic avatar Sep 29 '23 22:09 MilanKovacic