-
-
Notifications
You must be signed in to change notification settings - Fork 432
Conversation
I think the functionality is great - and certainly something that would be useful. Whether the syntax conforms is a different question. I'm wondering if something at the app level:
|
I don't think this should be handled by Svelte. Also, the |
Does subscribing to the |
How should that prevent the navigation? |
When this will be merged? It will solve lot of use cases where you have to control page navigation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could use some docs added under site/content/docs/
explaining the usage. That will also make the code easier to review. E.g. right now I'm not quite sure what the return value of onNavigate
is used for
I wonder if using the browser's beforeunload
would be a better way to handle this than introducing canNavigate
since it also covers the case where the user is closing the tab
My other question is whether we can have a method that's called before navigation and one that's called after navigation. Rich had suggested in https://github.com/sveltejs/sapper/issues/1278 introducing a method onNavigate
would be called after navigation, so maybe the onNavigate
here should be called onBeforeNavigate
const callbacks: OnNavigateCallback[] = []; | ||
|
||
export default function onNavigate(callback: OnNavigateCallback): () => void { | ||
if (!callbacks.includes(callback)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to check if the callback is already present?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise the callback could be added (and then later called) multiple times.
True.
You are right, |
Sorry this had gone unreviewed for so long. It looks like there's quite the merge conflict here. I don't think we'll be adding much functionality to Sapper at this point, but there is a ticket to add |
Fixes #1040
It works exactly like the example in my comment + you can return a promise inside
onNavigate
.