Support canonical URL
Open
Nobody has claimed this yet.
discussion
enhancement
v2
- Dominant language
- TypeScript
- Stars
- 11.2k
- Forks
- 899
- Avg merge
- 2d 24m
- Merged PRs (30d)
- 40
Description
ref https://github.com/nuxt/nuxt/issues/24813
Today, we expose useRequestURL() utility to access the current request URL however it can be tricky in two situations:
- In SSG, we cannot access the desired URL
- In runtime, sometimes, we need a canonical URL different from the incoming request
- In cached event handlers, we don't have access to incoming headers without opting more headers to
varies(which can also lead to cache leaks) - When we require a full URL for generating content there is no one standard way to depend on
- With fetch(/path) we need a default host (instead of assuming localhost)
Proposal:
- Support
app.canonicalURLin runtimeConfig for env support + app config for dynamic behavior support (prefer app) - Use canonical URL as default fallback for
useRequestURL() - Introduce new
useCanonicalURL()(suggested by @Atinux) that falls back touseRequestURL()if the user hasn't configured a canonical URL and fails for SSG if not provided
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the existing useRequestURL() utility and the runtimeConfig and app config handling referenced in the proposal. Trace how URLs are resolved in SSG, runtime requests, cached event handlers, and fetch(/path). Done means app.canonicalURL and a useCanonicalURL() fallback are supported, with the stated SSG failure behavior when no canonical URL is configured.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100