Skip to content

Commit 2a0e993

Browse files
committed
feat: expose compilePath to public api
1 parent 732f515 commit 2a0e993

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react';
2+
import { PathFunction as PathGeneratorFunction } from 'path-to-regexp'
23

34
export interface Route {
45
path: string;
@@ -51,9 +52,10 @@ export function getRoute(routeName: string): Route;
5152
export function getPathGenerator(
5253
routeName: number,
5354
scope?: string
54-
): (args?: RouteParams) => string;
55+
): PathGeneratorFunction<RouteParams>;
5556
export function generatePath(
5657
routeName: number,
5758
args?: RouteParams,
5859
scope?: string
5960
): string;
61+
export function compilePath(path: string): PathGeneratorFunction;

index.js.flow

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ export interface LinkProps {
4444
scope?: string;
4545
}
4646

47+
export type PathGeneratorFunction = (
48+
data?: RouteParams,
49+
options?: {}
50+
) => string;
51+
4752
declare export var Pagination: React.ComponentType<PaginationProps>;
4853
declare export var Link: React.ComponentType<LinkProps>;
4954

@@ -52,9 +57,10 @@ declare export function getRoute(routeName: string): Route;
5257
declare export function getPathGenerator(
5358
routeName: number,
5459
scope?: string
55-
): (args?: RouteParams) => string;
60+
): PathGeneratorFunction;
5661
declare export function generatePath(
5762
routeName: number,
5863
args?: RouteParams,
5964
scope?: string
6065
): string;
66+
declare export function compilePath(path: string): PathGeneratorFunction;

src/api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ export function generatePath (routeName, args = {}, scope) {
4545
return getPathGenerator(routeName, scope)(args)
4646
}
4747

48+
export { compilePath }
4849
export { Pagination, Link } from './components'

0 commit comments

Comments
 (0)