mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
chore: remove useless navigation duplicated
This commit is contained in:
parent
12cadc42a1
commit
7bf95d4bcf
@ -1,44 +1,28 @@
|
|||||||
/**
|
/**
|
||||||
* Vue Router support
|
* Vue Router support
|
||||||
*/
|
*/
|
||||||
import { getCurrentInstance, ComponentPublicInstance } from 'vue';
|
import {
|
||||||
|
PropType,
|
||||||
|
ExtractPropTypes,
|
||||||
|
getCurrentInstance,
|
||||||
|
ComponentPublicInstance,
|
||||||
|
} from 'vue';
|
||||||
import type { RouteLocation } from 'vue-router';
|
import type { RouteLocation } from 'vue-router';
|
||||||
|
|
||||||
export type RouteProps = {
|
export const routeProps = {
|
||||||
url?: string;
|
to: [String, Object] as PropType<RouteLocation>,
|
||||||
replace?: boolean;
|
url: String,
|
||||||
to?: RouteLocation;
|
replace: Boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type RouteConfig = {
|
export type RouteProps = ExtractPropTypes<typeof routeProps>;
|
||||||
url?: string;
|
|
||||||
to?: RouteLocation;
|
|
||||||
replace?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
function isRedundantNavigation(err: Error) {
|
|
||||||
return (
|
|
||||||
err.name === 'NavigationDuplicated' ||
|
|
||||||
// compatible with vue-router@3.3
|
|
||||||
(err.message && err.message.indexOf('redundant navigation') !== -1)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function route(vm: ComponentPublicInstance<RouteProps>) {
|
export function route(vm: ComponentPublicInstance<RouteProps>) {
|
||||||
const router = vm.$router;
|
const router = vm.$router;
|
||||||
const { to, url, replace } = vm;
|
const { to, url, replace } = vm;
|
||||||
|
|
||||||
if (to && router) {
|
if (to && router) {
|
||||||
const promise = router[replace ? 'replace' : 'push'](to);
|
router[replace ? 'replace' : 'push'](to);
|
||||||
|
|
||||||
/* istanbul ignore else */
|
|
||||||
if (promise && promise.catch) {
|
|
||||||
promise.catch((err) => {
|
|
||||||
if (err && !isRedundantNavigation(err)) {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else if (url) {
|
} else if (url) {
|
||||||
replace ? location.replace(url) : (location.href = url);
|
replace ? location.replace(url) : (location.href = url);
|
||||||
}
|
}
|
||||||
@ -50,9 +34,3 @@ export function useRoute() {
|
|||||||
route(vm);
|
route(vm);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const routeProps = {
|
|
||||||
url: String,
|
|
||||||
replace: Boolean,
|
|
||||||
to: [String, Object],
|
|
||||||
};
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user