File tree 2 files changed +15
-3
lines changed
test/fixtures/apps/app-ts/app/controller
2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -546,15 +546,15 @@ declare module 'egg' {
546
546
headers : { [ key : string ] : string } ;
547
547
}
548
548
549
- export interface Router extends KoaRouter < any , Context > {
549
+ export interface Router extends Omit < KoaRouter < any , Context > , 'url' > {
550
550
/**
551
551
* restful router api
552
552
*/
553
553
resources ( name : string , prefix : string , ...middleware : any [ ] ) : Router ;
554
554
555
555
/**
556
556
* @param {String } name - Router name
557
- * @param {Object } params - more parameters
557
+ * @param {Object } [ params] - more parameters
558
558
* @example
559
559
* ```js
560
560
* router.url('edit_post', { id: 1, name: 'foo', page: 2 })
@@ -565,7 +565,12 @@ declare module 'egg' {
565
565
* @return {String } url by path name and query params.
566
566
* @since 1.0.0
567
567
*/
568
- url ( name : string , params : any ) : any ;
568
+ url ( name : string , params ?: any ) : string ;
569
+ /**
570
+ * Alias for the url method
571
+ */
572
+ pathFor ( name : string , params ?: any ) : string ;
573
+ methods : string [ ] ;
569
574
}
570
575
571
576
export interface EggApplication extends EggCoreBase < EggAppConfig > { // tslint:disable-line
Original file line number Diff line number Diff line change @@ -30,6 +30,13 @@ export default class FooController extends Controller {
30
30
this . fooLogger = ctx . getLogger ( 'foo' ) ;
31
31
assert ( ctx . app . ctxStorage ) ;
32
32
assert ( ctx . app . currentContext ) ;
33
+
34
+ // router
35
+ console . log ( ctx . app . router . url ( 'foo' ) ) ;
36
+ console . log ( ctx . app . router . url ( 'foo' , { } ) ) ;
37
+ console . log ( ctx . app . router . pathFor ( 'foo' ) ) ;
38
+ console . log ( ctx . app . router . pathFor ( 'foo' , { } ) ) ;
39
+ console . log ( ctx . app . router . methods ) ;
33
40
}
34
41
35
42
async getData ( ) {
You can’t perform that action at this time.
0 commit comments