quartz
quartz copied to clipboard
Relative alias redirects fail when using SPA and navigating up directories
Describe the bug
I am authoring long-form content that does not use an index.md
. Instead, the entrypoint .md
for a given dir has frontmatter like
...
aliases:
- index
This allows me to have a content/
file structure like
content/
chapters/
chapter-1-name.md <--(this is aliased to index)
chapter-2-name.md
...
main-title-of-content.md <--(this is aliased to index)
other-arbitrary.md
metadata-pages.md
However when using enableSPA: true
, links such as the breadcrumbs that point up one or more directories behave incorrectly. In the example above, the "Home" breadcrumb on /chapters/chapter-n-name
will result in the browser navigating to /chapters/main-title-of-content
instead of /main-title-of-content
.
This appears to be because the content of the redirect is fetch
'd and then patched into the current page using minimorph
without rewriting the url in the meta tag, causing the redirect to be applied relative to the current path instead of the path the alias resides at.
To Reproduce Steps to reproduce the behavior:
- Ensure
quartz.config.ts
hasenableSPA: true
- Have a
content/
root withoutindex.md
- Add a file (e.g.
faux-index.md
) with frontmatter containingaliases: [index]
(or multiline version) - Add a file to a subdirectory (e.g.
demo/child-page.md
) - Start local server with
npx quartz build --serve
- Visit the child page in your browser, then click the "Home" breadcrumb
Expected behavior Quartz navigates to the aliased content at the unnested path.
Screenshots and Source
I have created a minimal reproduction https://github.com/joequincy/quartz-spa-repro/commit/b64659214988e52f35ebcbb46de7e3a314569569 with two pages. Just run npx quartz build --serve
on the repro
branch.
Desktop (please complete the following information):
- Quartz Version: 4.2.3
-
node
Version: 20.9.0 -
npm
version: 10.8.1 - OS: Ubuntu (via Windows 11 WSL2)
- Browser: Chrome
Additional context
I have also found what appears to be the source of the issue, and produced a potential fix on my reproduction. https://github.com/joequincy/quartz-spa-repro/commit/36703feb9e2c121945281a4d6b9d3dafa5af8a87 is on a separate potential-fix
branch for local testing.