scullyio / scully

The Static Site Generator for Angular apps

Home Page:https://scully.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ScullyRoutesService getCurrent does not produce values in case of using baseHref

rqman opened this issue · comments

🐞 Bug report

Description

🔬 Minimal Reproduction

  • add plugin base-href-rewrite with any custom value (i.e. /docs/) into scully configuration
  • generate site and subscribe to ScullyRoutesService#getCurrent()

💻Your Environment

Angular Version:

13.10.1

Scully Version:

2.1.36

🔥 Exception or Error

Expected behaviour:

  • ScullyRoutesService#getCurrent() should emit new value on route will be change

Actual behaviour:

  • ScullyRoutesService#getCurrent() should emit null

Root cause of the issue:

ScullyRoutesService load routes from the assets/scully-routes.json and that file contains routes without specified baseHref


allRoutes$: Observable = this.refresh.pipe(
    switchMap(() => this.http.get('assets/scully-routes.json')),
...

and when calculate getCurrent


getCurrent(): Observable {
    ...

    return merge(of(new NavigationEnd(0, '', '')), this.router.events).pipe(
      filter((e) => e instanceof NavigationEnd),
      switchMap(() => this.available$),
      map((list) => {
        // NOTE: location.pathname - contains specified `baseHref`...
        const curLocation = basePathOnly(encodeURI(location.pathname).trim());
        return list.find(
          (r) =>
           // NOTE:  ... but `r.route` has no specified `baseHref`
            curLocation === basePathOnly(r.route.trim()) ||
            (r.slugs &&
              Array.isArray(r.slugs) &&
              r.slugs.find((slug) =>
                curLocation.endsWith(basePathOnly(slug.trim()))
              ))
        );
      })
    );
  }