Skip to content

Instantly share code, notes, and snippets.

@renoirb
Created February 16, 2021 22:43
Show Gist options
  • Save renoirb/e669f0814c22d46f92012363373e9651 to your computer and use it in GitHub Desktop.
Save renoirb/e669f0814c22d46f92012363373e9651 to your computer and use it in GitHub Desktop.
single-spa notes

Single SPA Notes

/**
 * Somehow, we have to handle a different route to listen request for route change events
 * based on the pathname.
 * The pathname may either be from root (i.e. production), but for testing, we want it
 * to run from another path.
 *
 * See also
 *
 * singleSpaNavigate(`${window.location.pathname.replace('/main')}/call`)
 *
 * window.dispatchEvent(new CustomEvent("single-spa:routing-event", { detail: {} })); originalEvent
 *
 * window.addEventListener('single-spa:routing-event', evt => {
 *   console.log('single-spa:routing-event', evt || null);
 *   if(evt && evt.type) {
 *     evt.preventDefault();
 *   }
 *   console.log(evt.detail.originalEvent); // PopStateEvent
 *   console.log(evt.detail.newAppStatuses); // { app1: MOUNTED, app2: NOT_MOUNTED }
 *   console.log(evt.detail.appsByNewStatus); // { MOUNTED: ['app1'], NOT_MOUNTED: ['app2'] }
 *   console.log(evt.detail.totalAppChanges); // 2
 * });
 *
 * Bookmarks:
 * - https://single-spa.js.org/docs/api/#configuration-object
 * - https://single-spa.js.org/docs/ecosystem-react
 */
export const createRouteSlug = (slug = '/'): string => {
  const out = slug.replace(/\/\//g, '/')
  console.log(`1  createRouteSlug(${slug})`, out)
  // window.location.pathname+
  return out
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment