Skip to main content
Version: 3.4

createBasicRouter

Callable

  • createBasicRouter<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 our BasicCrawler. Defaults to the BasicCrawlingContext.

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

    import { BasicCrawler, createBasicRouter } from 'crawlee';

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

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

    Type parameters

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

    Parameters

    • optionalroutes: RouterRoutes<Context, UserData>

    Returns RouterHandler<Context>