routify
routify copied to clipboard
Support for Promise in beforeUrlChange
I would love to have support for Promise in $beforeUrlChange.
Currently, in a "form", I look if the form has some changes, and if yes, I show a dialog which returns a promise, that resolves after user's choice of whether to discard the change. It's pretty neat to wait for that response before I can return the $beforeUrlChange a "true" or "false".
Surprisingly, I am already using an asynchronous function there, but it pops out an incorrect type warning. I am not sure whether it's merely a fix for the types or actually needs to support in the codebase.
I am happy to provide more details as needed.
I thought this was already supported.
Are you using R2 or R3?
I am with R2, version 2.15.1. If you ignore VSCode complaining about the type error, it actually works just fine.
-- Here is a sidenote: Routify is amazingly awesome. Thanks to you, Ghost and everyone else involved in the community for active support and amazing ideas.
Can be fixed in this line I imagine @jakobrosenberg - https://github.com/roxiness/routify/blob/0a7eff304e781ecf30c686312fd765fdb90466db/typings/runtime/helpers.d.ts#L86
If this is valid jsdoc then it's as simple as:
(event?: PopStateEvent, route?: ClientNodeApi) => boolean}
to
(event?: PopStateEvent, route?: ClientNodeApi) => boolean | Promise<boolean>}
I have found the issue behind this. The types are automatically generated on build, but the type for beforeUrlChange was added manually in the generated definition file.
I'll try to sort this when I get home.