How to use the @aurelia/router.HookTypes.TransformToUrl function in @aurelia/router

To help you get started, we’ve selected a few @aurelia/router examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aurelia / aurelia / packages / __tests__ / router / hook-manager.spec.ts View on Github external
it('uses a TransformToUrl hook getting viewport instructions returning viewport instructions', async function () {
    const { router, tearDown, navigationInstruction } = await createFixture();

    const sut = new HookManager();
    sut.addHook(
      (viewportInstructions: ViewportInstruction[], navigationInstruction: INavigatorInstruction) =>
        Promise.resolve([router.createViewportInstruction(`hooked-${viewportInstructions[0].componentName}`)]),
      { type: HookTypes.TransformToUrl });

    const hooked = await sut.invokeTransformToUrl(
      [router.createViewportInstruction('testing')], navigationInstruction) as ViewportInstruction[];
    assert.strictEqual(hooked[0].componentName, 'hooked-testing', `hooked`);

    await tearDown();
  });
github aurelia / aurelia / packages / __tests__ / router / hook-manager.spec.ts View on Github external
it('sets a TransformToUrl hook with alternating types through api', async function () {
    const { router, tearDown, navigationInstruction } = await createFixture();

    const str = 'testing';

    let hooked: string | ViewportInstruction[] = await router.hookManager.invokeTransformToUrl(str, navigationInstruction) as string;
    assert.strictEqual(hooked, `${str}`, `not hooked`);

    const hookFunction = (input: string | ViewportInstruction[], navigationInstruction: INavigatorInstruction): Promise =>
      Promise.resolve(input.length > 0
        ? typeof input === 'string' ? [router.createViewportInstruction(`hooked-${input}`)] : `hooked-${input[0].componentName}`
        : input);

    router.addHook(hookFunction, { type: HookTypes.TransformToUrl });
    router.addHook(hookFunction, { type: HookTypes.TransformToUrl });
    router.addHook(hookFunction, { type: HookTypes.TransformToUrl });

    hooked = await router.hookManager.invokeTransformToUrl(str, navigationInstruction) as ViewportInstruction[];
    assert.strictEqual(hooked[0].componentName, `hooked-hooked-hooked-${str}`, `hooked-hooked-hooked`);

    await tearDown();
  });