本文整理汇总了TypeScript中react-router.match函数的典型用法代码示例。如果您正苦于以下问题:TypeScript match函数的具体用法?TypeScript match怎么用?TypeScript match使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了match函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: match
app.use((req, res) => {
match({
history: browserHistory,
location: req.url,
routes,
}, handleRoute(req, res))
})
示例2: match
const makeRoutes = (routes:any) => (callback:(routerProps:ReactRouter.MatchState)=>void) => {
match(
{ history
, routes
}
, (error, redirectLocation, routerProps) => callback(routerProps)
);
}
示例3: urlToRouterElement
export default function urlToRouterElement(url:string,routes:Object,cb:(err?:Error,status?:number,val?:any)=>void,attempts:number=0)
{
if(attempts > 100){
return cb(new Error('too many redirects'));
}
match(
{ routes: routes, location: url }
, function(error, redirectLocation, renderProps){
if (error) {
return cb(error);
} else if (redirectLocation) {
const _url = redirectLocation.pathname + redirectLocation.search;
return urlToRouterElement(_url,routes,cb,attempts+1);
} else if (renderProps) {
const isNotFound = renderProps.routes.some((route)=>route.path == '404')
const status = isNotFound ? 404 : 200;
return cb(null,status,renderProps);
}
return cb();
}
);
}
示例4: it
it("routes to the Search component", () => {
match({ location, routes }, (error: Error, nextLocation: Location, state: RouterContext.RouterContextProps) => {
expect((state.components![1] as any).WrappedComponent.name).toBe("Search")
})
})