base path refactor to better support subpath hosting
This commit is contained in:
		@@ -1,5 +1,5 @@
 | 
			
		||||
import micromorph from "micromorph"
 | 
			
		||||
import { CanonicalSlug, RelativeURL, getCanonicalSlug } from "../../util/path"
 | 
			
		||||
import { FullSlug, RelativeURL, getFullSlug } from "../../util/path"
 | 
			
		||||
 | 
			
		||||
// adapted from `micromorph`
 | 
			
		||||
// https://github.com/natemoo-re/micromorph
 | 
			
		||||
@@ -31,7 +31,7 @@ const getOpts = ({ target }: Event): { url: URL; scroll?: boolean } | undefined
 | 
			
		||||
  return { url: new URL(href), scroll: "routerNoscroll" in a.dataset ? false : undefined }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function notifyNav(url: CanonicalSlug) {
 | 
			
		||||
function notifyNav(url: FullSlug) {
 | 
			
		||||
  const event: CustomEventMap["nav"] = new CustomEvent("nav", { detail: { url } })
 | 
			
		||||
  document.dispatchEvent(event)
 | 
			
		||||
}
 | 
			
		||||
@@ -81,7 +81,7 @@ async function navigate(url: URL, isBack: boolean = false) {
 | 
			
		||||
  const elementsToAdd = html.head.querySelectorAll(":not([spa-preserve])")
 | 
			
		||||
  elementsToAdd.forEach((el) => document.head.appendChild(el))
 | 
			
		||||
 | 
			
		||||
  notifyNav(getCanonicalSlug(window))
 | 
			
		||||
  notifyNav(getFullSlug(window))
 | 
			
		||||
  delete announcer.dataset.persist
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -129,7 +129,7 @@ function createRouter() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
createRouter()
 | 
			
		||||
notifyNav(getCanonicalSlug(window))
 | 
			
		||||
notifyNav(getFullSlug(window))
 | 
			
		||||
 | 
			
		||||
if (!customElements.get("route-announcer")) {
 | 
			
		||||
  const attrs = {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user