mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-06 16:20:26 +08:00
create vue-router.d.ts
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
/// <reference path="./vue-router.d.ts" />
|
||||
|
||||
Vue.use(VueRouter);
|
||||
|
||||
namespace TestBasic {
|
||||
"use strict";
|
||||
|
||||
var Foo = Vue.extend({
|
||||
template: "<p>This is foo!</p>",
|
||||
route: {
|
||||
canActivate(transition: vuerouter.Transition<any, any, any, any, any>) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var Bar = Vue.extend({
|
||||
template: "<p>This is bar!</p>"
|
||||
});
|
||||
|
||||
var App = Vue.extend({});
|
||||
|
||||
var router = new VueRouter<typeof App.prototype>();
|
||||
|
||||
router.map({
|
||||
"/foo": {
|
||||
component: Foo
|
||||
},
|
||||
"/bar": {
|
||||
component: Bar
|
||||
}
|
||||
});
|
||||
|
||||
router.start(App, "#app");
|
||||
}
|
||||
|
||||
namespace TestAdvanced {
|
||||
"use strict";
|
||||
|
||||
namespace App {
|
||||
|
||||
export class App {
|
||||
authenticating: boolean;
|
||||
|
||||
data() {
|
||||
return {
|
||||
authenticating: false
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Inbox {
|
||||
export class Index {
|
||||
static route: vuerouter.TransitionHook<App.App, any, any, { id: number }, any> = {
|
||||
canActivate: function(transition) {
|
||||
var n: number = transition.to.params.id;
|
||||
transition.next();
|
||||
},
|
||||
activate: function() {
|
||||
return new Promise((resolve) => {
|
||||
resolve();
|
||||
});
|
||||
},
|
||||
deactivate: function({next}) {
|
||||
next();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace RouteConfig {
|
||||
export function configRouter(router: vuerouter.Router<App.App>) {
|
||||
router.map({
|
||||
"/about": {
|
||||
component: {},
|
||||
auth: false
|
||||
},
|
||||
"*": {
|
||||
component: {}
|
||||
}
|
||||
});
|
||||
|
||||
router.redirect({
|
||||
"/info": "/about",
|
||||
"/hello/:userId": "/user/:userId"
|
||||
});
|
||||
|
||||
router.beforeEach((transition) => {
|
||||
if (transition.to.path === "/forbidden") {
|
||||
router.app.authenticating = true;
|
||||
setTimeout(() => {
|
||||
router.app.authenticating = false;
|
||||
alert("");
|
||||
transition.abort();
|
||||
}, 3000);
|
||||
} else {
|
||||
transition.next();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
import configRouter = RouteConfig.configRouter;
|
||||
|
||||
const router = new VueRouter<App.App>({
|
||||
history: true,
|
||||
saveScrollPosition: true
|
||||
});
|
||||
|
||||
configRouter(router);
|
||||
router.start(App, "#app");
|
||||
}
|
||||
Vendored
+87
@@ -0,0 +1,87 @@
|
||||
// Type definitions for vue-router 0.7.7
|
||||
// Project: https://github.com/vuejs/vue-router
|
||||
// Definitions by: kaorun343 <https://github.com/kaorun343>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../vue/vue.d.ts" />
|
||||
/// <reference path="../es6-promise/es6-promise.d.ts" />
|
||||
|
||||
declare namespace vuerouter {
|
||||
|
||||
interface Transition<RootVueApp, FromParams, FromQuery, ToParams, ToQuery> {
|
||||
from: $route<RootVueApp, FromParams, FromQuery>;
|
||||
to: $route<RootVueApp, ToParams, ToQuery>;
|
||||
next(data?: any): void;
|
||||
abort(reason?: any): void;
|
||||
redirect(path: string): void;
|
||||
}
|
||||
|
||||
interface RouterOption {
|
||||
hashbang?: boolean;
|
||||
history?: boolean;
|
||||
abstract?: boolean;
|
||||
root?: string;
|
||||
linkActiveClass?: string;
|
||||
saveScrollPosition?: boolean;
|
||||
transitionOnLoad?: boolean;
|
||||
suppressTransitionError?: boolean;
|
||||
}
|
||||
|
||||
interface RouterStatic {
|
||||
new <RootVueApp>(option?: RouterOption): Router<RootVueApp>;
|
||||
}
|
||||
|
||||
interface RouteMapObject {
|
||||
component: any;
|
||||
subRoutes?: { [key: string]: RouteMapObject };
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface Router<RootVueApp> {
|
||||
|
||||
app: RootVueApp;
|
||||
mode: string;
|
||||
|
||||
start(App: any, el: string | Element): void;
|
||||
stop(): void;
|
||||
map(routeMap: { [path: string]: RouteMapObject }): void;
|
||||
on(path: string, config: Object): void;
|
||||
go(path: string | Object): void;
|
||||
replace(path: string): void;
|
||||
redirect(redirectMap: Object): void;
|
||||
alias(aliasMap: Object): void;
|
||||
beforeEach<FP, FQ, TP, TQ>(hook: (transition: Transition<RootVueApp, FP, FQ, TP, TQ>) => any): void;
|
||||
afterEach<FP, FQ, TP, TQ>(hook: (transition: Transition<RootVueApp, FP, FQ, TP, TQ>) => any): void;
|
||||
}
|
||||
|
||||
interface $route<RootVueApp, Params, Query> {
|
||||
path: string;
|
||||
params: Params;
|
||||
query: Query;
|
||||
router: Router<RootVueApp>;
|
||||
matched: string[];
|
||||
name: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface TransitionHook<Root, FP, FQ, TP, TQ> {
|
||||
data?(transition?: Transition<Root, FP, FQ, TP, TQ>): Thenable<any> | void;
|
||||
activate?(transition?: Transition<Root, FP, FQ, TP, TQ>): Thenable<any> | void;
|
||||
deactivate?(transition?: Transition<Root, FP, FQ, TP, TQ>): Thenable<any> | void;
|
||||
canActivate?(transition?: Transition<Root, FP, FQ, TP, TQ>): Thenable<any> | boolean | void;
|
||||
canDeactivate?(transition?: Transition<Root, FP, FQ, TP, TQ>): Thenable<any> | boolean | void;
|
||||
canReuse?: boolean | ((transition: Transition<Root, FP, FQ, TP, TQ>) => boolean);
|
||||
}
|
||||
}
|
||||
|
||||
declare namespace vuejs {
|
||||
interface ComponentOption {
|
||||
route?: vuerouter.TransitionHook<any, any, any, any, any>;
|
||||
}
|
||||
}
|
||||
|
||||
declare var VueRouter: vuerouter.RouterStatic;
|
||||
|
||||
declare module "vue-router" {
|
||||
export = VueRouter;
|
||||
}
|
||||
Reference in New Issue
Block a user