Skip to content

vue-router integration fails on beforeRoute* guards #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
silkentrance opened this issue Nov 15, 2017 · 6 comments
Closed

vue-router integration fails on beforeRoute* guards #193

silkentrance opened this issue Nov 15, 2017 · 6 comments

Comments

@silkentrance
Copy link

See https://gist.github.com/silkentrance/9caa45481329f6ef911bd5eae5dbb7c3

See also #192 (comment) for more information.

@silkentrance
Copy link
Author

@ktsn I am lazy 😁

@silkentrance
Copy link
Author

the solution would be to not register the guards on options.methods but directly on the options object itself, e.g.

if (typeof descriptor.value === 'function') {
      // methods
      options[key] = descriptor.value
    } else if (descriptor.get || descriptor.set) {
      // computed properties
      (options.computed || (options.computed = {}))[key] = {
        get: descriptor.get,
        set: descriptor.set
      }
    }

And AFAIK, options.computed will also not be interpreted by vue-router. So these need to be registered directly as properties of the options object, too.

@ktsn
Copy link
Member

ktsn commented Nov 15, 2017

router.ts still load the component before calling registerHook because all import statement will be hoisted and executed before all other statements.

Please try separate the registerHook in another file and import it before the component as same as docs.

@silkentrance
Copy link
Author

@ktsn which is the example provided. will try.

@silkentrance
Copy link
Author

@ktsn now it works as expected. still trying to figure out why. is there some second stage processing in vue-router or vue-class-component? anyway, thanks for your incredible help figuring this out. perhaps it should be made more clear in the documentation that registering the guards in a separate module is a vital step.

@johnsmithjsjs
Copy link

perhaps it should be made more clear in the documentation that registering the guards in a separate module is a vital step.

That would be reeeeaally great. I made the same mistake and spent a lot of time on this(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants