forked from vuejs/vue-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
566 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/*! | ||
* vue-router v3.5.4 | ||
* (c) 2022 Evan You | ||
* @license MIT | ||
*/ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
var vue = require('vue'); | ||
|
||
function useRouter () { | ||
var i = vue.getCurrentInstance(); | ||
if (process.env.NODE_ENV !== 'production' && !i) { | ||
throwNoCurrentInstance('useRouter'); | ||
} | ||
|
||
return i.proxy.$root.$router | ||
} | ||
|
||
function useRoute () { | ||
var i = vue.getCurrentInstance(); | ||
if (process.env.NODE_ENV !== 'production' && !i) { | ||
throwNoCurrentInstance('useRoute'); | ||
} | ||
|
||
var root = i.proxy.$root; | ||
if (!root._$route) { | ||
var route = vue.effectScope(true).run( | ||
function () { return vue.shallowReactive(Object.assign({}, root.$router.currentRoute)); } | ||
); | ||
root._$route = route; | ||
|
||
root.$router.afterEach(function (to) { | ||
Object.assign(route, to); | ||
}); | ||
} | ||
|
||
return root._$route | ||
} | ||
|
||
// TODO: | ||
// export function useLink () {} | ||
|
||
function onBeforeRouteUpdate (guard) { | ||
var i = vue.getCurrentInstance(); | ||
if (process.env.NODE_ENV !== 'production' && !i) { | ||
throwNoCurrentInstance('onBeforeRouteUpdate'); | ||
} | ||
|
||
var router = useRouter(); | ||
|
||
var target = i.proxy; | ||
// find the nearest routerview to know the depth | ||
while (target && target.$vnode && target.$vnode.data && target.$vnode.data.routerViewDepth == null) { | ||
target = target.$parent; | ||
} | ||
|
||
var depth = target && target.$vnode && target.$vnode.data ? target.$vnode.data.routerViewDepth : null; | ||
|
||
console.log('found depth', depth); | ||
|
||
// TODO: allow multiple guards? | ||
i.proxy.$options.beforeRouteUpdate = guard; | ||
|
||
var removeGuard = router.beforeEach(function (to, from, next) { | ||
// TODO: check it's an update | ||
return guard(to, from, next) | ||
}); | ||
|
||
vue.onUnmounted(removeGuard); | ||
|
||
return removeGuard | ||
} | ||
|
||
// TODO: | ||
// export function onBeforeRouteLeave () {} | ||
|
||
function throwNoCurrentInstance (method) { | ||
throw new Error( | ||
("[vue-router]: Missing current instance. " + method + "() must be called inside <script setup> or setup().") | ||
) | ||
} | ||
|
||
exports.onBeforeRouteUpdate = onBeforeRouteUpdate; | ||
exports.useRoute = useRoute; | ||
exports.useRouter = useRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/*! | ||
* vue-router v3.5.4 | ||
* (c) 2022 Evan You | ||
* @license MIT | ||
*/ | ||
import { getCurrentInstance, effectScope, shallowReactive, onUnmounted } from 'vue'; | ||
|
||
function useRouter () { | ||
var i = getCurrentInstance(); | ||
if (process.env.NODE_ENV !== 'production' && !i) { | ||
throwNoCurrentInstance('useRouter'); | ||
} | ||
|
||
return i.proxy.$root.$router | ||
} | ||
|
||
function useRoute () { | ||
var i = getCurrentInstance(); | ||
if (process.env.NODE_ENV !== 'production' && !i) { | ||
throwNoCurrentInstance('useRoute'); | ||
} | ||
|
||
var root = i.proxy.$root; | ||
if (!root._$route) { | ||
var route = effectScope(true).run( | ||
function () { return shallowReactive(Object.assign({}, root.$router.currentRoute)); } | ||
); | ||
root._$route = route; | ||
|
||
root.$router.afterEach(function (to) { | ||
Object.assign(route, to); | ||
}); | ||
} | ||
|
||
return root._$route | ||
} | ||
|
||
// TODO: | ||
// export function useLink () {} | ||
|
||
function onBeforeRouteUpdate (guard) { | ||
var i = getCurrentInstance(); | ||
if (process.env.NODE_ENV !== 'production' && !i) { | ||
throwNoCurrentInstance('onBeforeRouteUpdate'); | ||
} | ||
|
||
var router = useRouter(); | ||
|
||
var target = i.proxy; | ||
// find the nearest routerview to know the depth | ||
while (target && target.$vnode && target.$vnode.data && target.$vnode.data.routerViewDepth == null) { | ||
target = target.$parent; | ||
} | ||
|
||
var depth = target && target.$vnode && target.$vnode.data ? target.$vnode.data.routerViewDepth : null; | ||
|
||
console.log('found depth', depth); | ||
|
||
// TODO: allow multiple guards? | ||
i.proxy.$options.beforeRouteUpdate = guard; | ||
|
||
var removeGuard = router.beforeEach(function (to, from, next) { | ||
// TODO: check it's an update | ||
return guard(to, from, next) | ||
}); | ||
|
||
onUnmounted(removeGuard); | ||
|
||
return removeGuard | ||
} | ||
|
||
// TODO: | ||
// export function onBeforeRouteLeave () {} | ||
|
||
function throwNoCurrentInstance (method) { | ||
throw new Error( | ||
("[vue-router]: Missing current instance. " + method + "() must be called inside <script setup> or setup().") | ||
) | ||
} | ||
|
||
export { onBeforeRouteUpdate, useRoute, useRouter }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import VueRouter from '../router' | ||
|
||
export default VueRouter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import VueRouter from '../router' | ||
|
||
export const version = '__VERSION__' | ||
export { isNavigationFailure, NavigationFailureType } from '../util/errors' | ||
export { START as START_LOCATION } from '../util/route' | ||
|
||
// we can't add the other composables here because people could still be using an older version of vue and that would | ||
// create a compilation error trying to import from vue | ||
|
||
export default VueRouter |
Oops, something went wrong.