[improvement] unify mixin name (#2795)

This commit is contained in:
neverland
2019-02-19 16:04:29 +08:00
committed by GitHub
parent 8c6ab91f6d
commit 9d0255d9e1
49 changed files with 112 additions and 122 deletions

37
packages/utils/router.ts Normal file
View File

@@ -0,0 +1,37 @@
/**
* Vue Router support
*/
import { RenderContext } from 'vue/types';
import VueRouter, { RawLocation } from 'vue-router/types';
export type RouteConfig = {
url?: string;
to?: RawLocation;
replace?: boolean;
};
export function route(router: VueRouter, config: RouteConfig) {
const { to, url, replace } = config;
if (to && router) {
router[replace ? 'replace' : 'push'](to);
} else if (url) {
replace ? location.replace(url) : (location.href = url);
}
}
export function functionalRoute(context: RenderContext) {
route(context.parent && context.parent.$router, context.props);
}
export type RouteProps = {
url?: string,
replace?: boolean;
to?: RawLocation;
}
export const routeProps = {
url: String,
replace: Boolean,
to: [String, Object]
};