roxiness / routify

Automated Svelte routes
https://routify.dev
1.89k stars 88 forks source link

docs for `BeforeUrlChange` callback parameter #396

Closed benmccann closed 3 years ago

benmccann commented 3 years ago

I see in the docs that the callback has an event parameter, but I'm not quite sure what types of events might be passed in. I'm also slightly confused because the "type" is referred to as {Function(event, route):boolean}, but then the example shows (event, store) => { ... }, so I'm not sure if the second parameter is a route or a store.

jakobrosenberg commented 3 years ago

Thanks Ben, much appreciated. I'm not sure how route ended up as store in the example, but I've updated it so it's route in both.

benmccann commented 3 years ago

Thanks! Any details about the event question? Sorry for asking if you've updated that as well, but I'm not seeing the update anywhere

jakobrosenberg commented 3 years ago

Sorry. Completely missed the event question.

I hope this simplified version explains it.

  // eventName: 'pushstate' || 'replacestate'
  const event = new Event(eventName)

  // state, title and url are taken from the push/replaceState event that triggered the page change.
  // state is also assigned id, path and params from the current route.
  Object.assign(event, { state, title, url })

The serviceworker was recently updated and it's possible it's set to stale-while-revalidate in which case the site could take a little longer to update. If the issue persists I'll take a look at it.

ghostdevv commented 3 years ago

Just go to the site and give it a sec and it will say it's updated :smile:

benmccann commented 3 years ago

Thanks for the clarification on regarding event. I'm hoping to add something like BeforeUrlChange to SvelteKit, so wanted to see how you guys were handling it :wink: If y'all would be interested in adding some Routify features to SvelteKit at any point just let me know and I'd be happy to collaborate on it.

Unfortunately, the site still isn't updating for me. There's also another issue, which is that the #before-url-change anchor isn't working. When I visit https://routify.dev/docs/helpers#before-url-change I'm always taken to the top of the page instead of the appropriate section.

jakobrosenberg commented 3 years ago

I'm probably missing something here, but wouldn't the export const load = ()=>{} function handle that kind of logic?

If Routify 3 can be considered a feature in itself, I'm currently in the process of adding that😅.

Is there any specific you think Sveltekit could benefit from in terms of Routify features?

benmccann commented 3 years ago

load doesn't give you a way to run things before a route change, cancel a route change, etc. It just lets you load data on a page unless you had an idea of how to use it that I might have overlooked. It's been one of our biggest feature requests

I think the metadata and metatags features are another thing you can't do right now. There's another open issue about that

I haven't looked at how you've implemented transitions or if there are things there that are hard or not possible in SvelteKit

Those would probably be the ones that would make the most sense. I think that most of the others would already exist though I haven't looked super closely and could have missed some

ghostdevv commented 3 years ago

Unfortunately, the site still isn't updating for me. There's also another issue, which is that the #before-url-change anchor isn't working. When I visit https://routify.dev/docs/helpers#before-url-change I'm always taken to the top of the page instead of the appropriate section.

Will take a look at this! the r2 site is pretty gigantic so things slip through :grimacing:

I think the metadata and metatags features are another thing you can't do right now. There's another open issue about that

Metatags are super simple, just a context aware store that updates document.title and creates/updates meta, twitter, and open graph meta tags

Meta its self in r2 is a combination of build time meta (from things like the comments) and runtime from just updating the store yourself iirc

Those would probably be the ones that would make the most sense. I think that most of the others would already exist though I haven't looked super closely and could have missed some

The most useful helpers in Routify would probably be url, goto, redirect, params, and layout

==

I am not sure about the other bits you said, you'll have to wait for Jake - we'd love to help out where we can (I say we, I don't know how to do most of the magic he does xD)