question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is your feature request related to a problem? Please describe. Components that are used in layouts currently don’t have access to which route they’re being used on. The $page store tells us the underlying path and the params that have been extracted from that path, but doesn’t tell us anything about which route those params have meaning in.

When making a navbar in Sapper, I generally have to re-analyze $page.path with regexes or string comparisons or whatever in order to tell which page I’m on and what state the navbar should be in.

Describe the solution you’d like Since the framework has already decided which route this request maps to, it can expose this information in the $page store. The most immediately obvious way to me for this to be handled would be for the relative path to the .svelte file that is the page route be included as a string in (say) $page.route.

Describe alternatives you’ve considered If we didn’t want the inelegance or fragility of exposing file paths as strings, would be to let each page component expose - in some way - a user-specified key that Kit doesn’t do anything with apart from exposing in the $page store. This could be a separate module context export, or it could be another value in the load response, or maybe something else. This was also suggested in https://github.com/sveltejs/kit/issues/1459

How important is this feature to you? It’d be nice to have. That my code needs to re-figure out something about what page I’m on that the framework has already determined and then kept for itself is irritating.

Additional context None that I can think of right now.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:16
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
didiercommented, Nov 15, 2021

Would it be possible to implement an API similar to https://github.com/didier/sveo? I’d love to help where possible.

<script context="module">
  // /about.svelte
  export const metadata = {
    title: 'Hello world',
    description: 'Have a wonderful day.'
  }
</script>
<script context="module">
  // /__layout.svelte
  export const load = async ({ metadata }) => {
    // The metadata from the page component
    const { title, description } = metadata

    return {
      props: {
        title,
        description
      }
    }
  }
</script>

This would make SEO stuff a lot easier, since we can define titles and other data on a page level and have all the meta tags handled by the layout component.

2reactions
alteredorangecommented, Mar 25, 2021

I think this is important, because it looks like sveltekit doesn’t export segment like sapper did. (At least segment is always undefined when I export it from $layout). Currently I’m using $page.path.substring(1) for all my route needs, but it would be great if there was an actual route param, as I’m not sure the substring works with all edge cases.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's in the head? Metadata in HTML - MDN Web Docs
Metadata is data that describes data, and HTML has an "official" way of adding metadata to a document — the <meta> element. Of...
Read more >
SEO 101: Everything You Need To Know About Metadata
Your website metadata consists of a page title and meta description for every page. These provide search engines like Google with important ...
Read more >
HTML meta tag - W3Schools
Metadata is data (information) about data. <meta> tags always go inside the <head> element, and are typically used to specify character set, page...
Read more >
What Are Meta Descriptions And How to Write Them - Moz
A meta description is an HTML element that provides a brief summary of a web page. A page's meta description tag is displayed...
Read more >
Meta Tags and Attributes that Google Supports | Documentation
Google supports both page-level meta tags and tag attributes. Explore a list of the special tags that Google Search can support.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found