-
-
Notifications
You must be signed in to change notification settings - Fork 428
RFC: Remove segment
prop from layouts
#824
Comments
We could perhaps ease people into this a bit, by issuing warnings rather than immediately breaking. It should be pretty straightforward to check at build time whether a given |
As I mentioned, I have moved away from using Removing If we do choose to adopt this proposal, transitioning to it gently with a deprecation notice seems like a nice idea, especially since the |
I do find it useful for e.g. controlling which nav button is selected (including nested, secondary navs). If we were to remove this — and I agree, it's weird and vestigial — what about adding a |
I wondered about adding a segments array to the |
That's funny, I just started using Ideally exposing $page would be a bit less laborious, but I imagine there's a discussion on that elsewhere. |
|
Sorry, I meant exposing the reference to the page store. It feels a bit icky to have to |
I don't know what "icky" means. I think it is explicit and i like that. |
It's entirely subjective and appears to be derailing the discussion, so let's move on, I guess 😅 |
i like this idea. i'd love to also link this RFC in the docs to warn users. is this kind of PR welcome? |
One thing I believe can’t be done with |
Any updates on this? Having much difficulty wrapping my head around using <li>
<a
class={segment === 'about' ? 'selected' : ''}
href='about'
>
About
</a>
</li> ..but when i try to do the same thing with dynamic routes from slugs from markdown files, then no dice: <li>
<a
class={segment === 'team/{member.slug}' ? 'selected' : ''}
href='team/{member.slug}'
>
{member.name}
</a>
</li> ...which is a bit frustrating. Pretty confident I'm doing something wrong here, but discord has up to this point been no help. Also, getting odd warnings in the console without doing anything and just running the starter locally: ...would |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Previously I was very much in favour of getting rid of |
@rodoch do you have any code you can share that demonstrates the complication you're describing? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Sorry that your issue is deemed off-topic lol, it's a major problem that all people will run into. Anyway, best way I can find is to let it give you segment... then just use it as a body class. It is complaining you aren't using "segment"... so just swallow their opinionated "off-topic" marking bs and use it as a body class. This will get marked as off-topic so another 10,000 developers have to waste their time on it I imagine. Such is life. |
Either stop marking comments as off-topic or fix the issue. You're wasting peoples' time that they use to feed their families. |
I don't know whether it's off-topic or not since I'm not yet familiar with Svelte/Sapper. I've been using Vue for several years, and React for several years before that. I find it strange that such an issue crops up with something that is basically the official Sapper starter template. On searching, this is the issue that seemed closest to what I'm looking at. But I certainly agree the behaviour of marking off-topic without any explanation or direction to where one should be looking is pretty useless. |
@jazoom "use it as a body class" -> Put that in your pipe and smoke it |
Nothing in a public repo, but I can demonstrate with some pseudo-code. For example, I have a site with several different sections.
There is a main site navigation and then each section has it's own subnavigation. The URL structure looks like:
The subnavigation for each section is different and is contained in each section's <script>
export let segment;
</script>
<ul>
<li>
<a href='./page1' class:active={segment==='page1'}>Page 1</a>
</li>
<li>
<a href='./page2' class:active={segment==='page2'}>Page 2</a>
</li>
<li>
<a href='./page3' class:active={segment==='page3'}>Page 3</a>
</li>
etc. ...
</ul> If the import { stores } from '@sapper/app';
const { page } = stores();
function getParam(paramIndex) {
if (!$page.path || $page.path === '/') return ``;
let params = $page.path.split('/');
return params[paramIndex];
// + more guards, etc. ...
} However, because the This isn't a deal-breaker, so if you'd rather see it gone that's fine. But if it's not doing any particular harm and it's not standing in the way of any architectural progress it would be nice to see it stay. I can see the the unused prop warning, though harmless, is evidently annoying some people in this thread but perhaps there would be some way to quash this? |
hmm,, on
|
That seems to be all it wants. You don't even need to negate it. This little hack is enough to get it to stop giving warnings.
|
oh yeah, haha,, why i even do that,, edit: i remember doing that so it will not create a warning by the IDE |
I also use segment over 30 times in production (two different apps) and would be sad to lose it. |
Just in case I'll reference to my comment #1545 (comment) before people actually start working on this. |
Just to back up my statement above a little further, you can look at a production app made using Sapper here: https://www.gaois.ie/. As well as the main navigation, I accept that there are many applications that don't need any kind of subnavigation or nested layouts but the more people build larger, fully-featured sites with Sapper the more this use case will crop up IMO. |
The code doesn't seem like it's much different if you were to use the page store instead of
|
Fair point, and maybe my example is at fault there. Both my pseudo-code and your suggestion presume that https://www.gaois.ie/en/technology/developers/login/ The sub-menu on the left here uses https://www.gaois.ie/en/technology/developers/ The solution above would not work in this situation - you can't rely on |
Can't we just leave |
Nothing will ever make me happy. |
I recently upgraded sapper (
I am in favor of removing segment, if it helps me have a more concise way to get rid of these warnings. As an alternative, maybe sapper could provide a utility library for accessing segments of the URL navigation / routing so we don't have to write as much EDIT: import { pageSegment } from '@sapper/app';
const segment = pageSegment(); I think you could maintain some level of backwards compatibility with this method. |
With the introduction of the
page
store in Svelte v3 Sapper, thesegment
prop passed to_layout.svelte
components feels somewhat vestigial. I don't think there's anything that can be done with it that can't be done (in a more uniform, if slightly more verbose, way) with$page.path
.There seems to be a bit of confusion around
segment
, about how to gain access to other parts of the URL, and about how to inject other bits of data into the layout. These would hopefully all be avoided if we never actually passed any props into_layout
and we instead had the docs tell people to just always use the stores.Thoughts?
The text was updated successfully, but these errors were encountered: