Skip to content

Commit

Permalink
feat: add this.$route
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Apr 16, 2020
1 parent cf6d3c3 commit 92dc18d
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 92dc18d

Please sign in to comment.