mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-10 10:21:55 +00:00
Fix useRoute helper
This commit is contained in:
parent
52d62f7801
commit
ff6e1d3ddb
|
@ -1,14 +1,34 @@
|
|||
// TODO: This helper can be removed once
|
||||
// vue-router either releases a new version, or we update to vue3.
|
||||
import { getCurrentInstance } from 'vue';
|
||||
import { effectScope, getCurrentInstance, reactive } from 'vue';
|
||||
|
||||
export function useRoute() {
|
||||
import { Route } from 'vue-router';
|
||||
|
||||
let currentRoute: Route;
|
||||
|
||||
function assign(target: Record<string, any>, source: Record<string, any>) {
|
||||
for (const key of Object.keys(source)) {
|
||||
target[key] = source[key];
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
export function useRoute(): Route {
|
||||
const inst = getCurrentInstance();
|
||||
if (!inst) {
|
||||
throw new Error('No current instance found');
|
||||
return undefined as any;
|
||||
}
|
||||
const { proxy } = inst;
|
||||
return proxy.$route;
|
||||
if (!currentRoute) {
|
||||
const scope = effectScope(true);
|
||||
scope.run(() => {
|
||||
const { $router } = inst.proxy;
|
||||
currentRoute = reactive(assign({}, $router.currentRoute)) as any;
|
||||
$router.afterEach((to) => {
|
||||
assign(currentRoute, to);
|
||||
});
|
||||
});
|
||||
}
|
||||
return currentRoute;
|
||||
}
|
||||
export function useRouter() {
|
||||
const inst = getCurrentInstance();
|
||||
|
|
Loading…
Reference in New Issue
Block a user