From: Eduardo San Martin Morote Date: Thu, 16 Apr 2020 14:40:47 +0000 (+0200) Subject: feat: add this.$route X-Git-Tag: v4.0.0-alpha.6~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=92dc18d448ffeb57d9b3f3b303b8ec2991175eb5;p=thirdparty%2Fvuejs%2Frouter.git feat: add this.$route --- diff --git a/src/router.ts b/src/router.ts index 35c923cd..f7f054d7 100644 --- a/src/router.ts +++ b/src/router.ts @@ -578,20 +578,17 @@ function applyRouterPlugin(app: App, router: Router) { app.component('RouterLink', Link) app.component('RouterView', View) + // TODO: add tests + // @ts-ignore + app.config.globalProperties.$router = router + Object.defineProperty(app.config.globalProperties, '$route', { + get: () => router.currentRoute.value, + }) + let started = false // TODO: can we use something that isn't a mixin? Like adding an onMount hook here app.mixin({ beforeCreate() { - // TODO: add tests - this.$router = this.$parent ? this.$parent.$router : router - // TODO: find a way to allow $route without having to write $route.value - // this.$route = this.$parent ? this.$parent.$route : this.route - - // this doesn't work because `this` is a Proxy - // Object.defineProperty(this, '$route', { - // get: () => router.currentRoute.value, - // }) - if (isBrowser && !started) { // this initial navigation is only necessary on client, on server it doesn't make sense // because it will create an extra unnecessary navigation and could lead to problems