Skip to main content
Version: 3.5

createJSDOMRouter

Callable

  • createJSDOMRouter<Context, UserData>(routes?: RouterRoutes<Context, UserData>): RouterHandler<Context>

  • Creates new Router instance that works based on request labels. This instance can then serve as a requestHandler of your JSDOMCrawler. Defaults to the JSDOMCrawlingContext.

    Serves as a shortcut for using Router.create<JSDOMCrawlingContext>().

    import { JSDOMCrawler, createJSDOMRouter } from 'crawlee';

    const router = createJSDOMRouter();
    router.addHandler('label-a', async (ctx) => {
    ctx.log.info('...');
    });
    router.addDefaultHandler(async (ctx) => {
    ctx.log.info('...');
    });

    const crawler = new JSDOMCrawler({
    requestHandler: router,
    });
    await crawler.run();

    Type parameters

    • Context: JSDOMCrawlingContext<any, any> = JSDOMCrawlingContext<any, any>
    • UserData: Dictionary = GetUserDataFromRequest<Context[request]>

    Parameters

    • optionalroutes: RouterRoutes<Context, UserData>

    Returns RouterHandler<Context>