Preload full page url #1016
Description
Is your feature request related to a problem? Please describe.
When trying to add opengraph meta tags it isn't possible to retrieve the current page url without it being broken down into its parts. This requires either rebuilding the url for the og:url meta tag or manually typing it.
Describe the solution you'd like
The preload function's page parameter should have a fully qualified URL / href.
Describe alternatives you've considered
<script context="module">
const queryToUrl = async query =>
Object.entries(query)
.map(entry => (entry[1] ? entry.join("=") : entry[0]))
.join("&");
const getUrlFromPage = async ({ host, path, query }) => {
const queryUrl = await queryToUrl(query);
return `https://${host}${path}${queryUrl.length ? `?${queryUrl}` : ""}`;
};
export function preload(page) {
return getUrlFromPage(page).then(url => ({content: url}));
}
</script>
<script>
export let content;
</script>
<svelte:head>
<meta property="og:url" {content} />
</svelte:head>
How important is this feature to you?
This is hard to quantify... I don't believe this is a major change, but it would make programmatically accessing the current page's url much easier for server side rendering.
Additional context
onMount cannot be used to access window.location.href because that only works on the clientside, and the whole point of the meta tags is for open graph services to just read the head of the page as delivered by SSR.
<script>
import {onMount} from 'svelte';
let content;
onMount(() => {
content = window.location.href;
});
</script>
<svelte:head>
<meta property="og:url" {content} />
</svelte:head>
This will result in the SSR version having content='' and being updated to the correct value only after the page is loaded into a browser.