2

I have been looking around trying to find an answer to this problem but I can't, apologies if this has already been asked!

I have created some small angular 9 apps which I am importing into a basic html page using single spa. I have my apps running on different ports locally, my import statement looks like this:

  <script type="systemjs-importmap">
  {
    "imports": {
      "footer": "http://localhost:4201/main.js",
      "dashboard": "http://localhost:4202/main.js",
      "header": "http://localhost:4300/main.js",
      "single-spa": "https://cdnjs.cloudflare.com/ajax/libs/single-spa/4.3.5/system/single-spa.min.js"
    }
  }
</script>

And I have routes in my html page so that the apps show up on different routes, this is one item from the registration of the applications I am importing:

    System.import('single-spa').then(function (singleSpa) {
  singleSpa.registerApplication(
    'header',
    function () {
      return System.import('header');
    },
    function (location) {
      return location.pathname.startsWith('/header');
      // return true;
    }
  )

THis all works well and my simple apps show up as they should. The problem arises when I try to add some child pages into my simple apps and route to those in my main "shell" app, if I navigate to "localhost:4200/header", the "header" app I imported shows up correctly. If I try and navigate within that app to a child page, for example this child route I have set up in the "header" app "app-routing-module":

  { path: '**', component: EmptyRouteComponent, children: [
{path: 'sub-details', component: DetailsComponent}

] },

Nothing happens. I have a <router-outlet></router-outlet> on my "header" app's landing page along with a link like this: <a [routerLink]="['./dets']">Dets</a> but instead of routing in the main app to "localhost:4200/header/dets" angular routes to "localhost:4200/dets" which of course doesn't exist. Does anybody have any ideas of what I am missing? Any help would be greatly appreciated!

webdevz12
  • 33
  • 2
  • 5
  • This seems directly related to the note mentioned in the single-spa-angular 'Configure routes' section https://single-spa.js.org/docs/ecosystem-angular/#configure-routes "[It] is recommended using '/' as APP_BASE_HREF and repeat the url prefix for your Angular app in every route component and router links. If you set /angular in your Angular app activity function for mount when the url starts with this value you'll have to add /angular prefix in all links." – filoxo May 14 '20 at 18:48
  • Thank you for your help, that's exactly what the problem was! – webdevz12 May 15 '20 at 18:42

1 Answers1

0

This seems directly related to the note mentioned in the single-spa-angular 'Configure routes' section single-spa.js.org/docs/ecosystem-angular/#configure-routes "[It] is recommended using '/' as APP_BASE_HREF and repeat the url prefix for your Angular app in every route component and router links. If you set /angular in your Angular app activity function for mount when the url starts with this value you'll have to add /angular prefix in all links." – filoxo