How to use the @aurelia/router.RouteRecognizer 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 / route-recognizer.spec.ts View on Github external
it('should find handlers by route name', function () {
    const sut = new RouteRecognizer();
    sut.add([staticRoute]);

    assert.strictEqual(sut.hasRoute('static'), true, `sut.hasRoute('static')`);
    assert.strictEqual(sut.handlersFor('static')[0].handler, staticRoute.handler, `sut.handlersFor('static')[0].handler`);
  });
github aurelia / aurelia / packages / __tests__ / router / route-recognizer.spec.ts View on Github external
it('should register unnamed routes', function () {
    const sut = new RouteRecognizer();
    sut.add([{'path': 'b', 'handler': {}}]);

    assert.deepStrictEqual(sut.names, {}, `sut.names`);
    assert.strictEqual(!!sut.recognize('/b'), true, `!!sut.recognize('/b')`);
  });
github aurelia / aurelia / packages / __tests__ / router / route-recognizer.spec.ts View on Github external
it('should find a handler by multiple names', function () {
    const sut = new RouteRecognizer();
    sut.add([multiNameRoute]);

    assert.strictEqual(
      sut.handlersFor('static-multiple')[0].handler,
      sut.handlersFor('static-multiple-alias')[0].handler
    );
  });
github aurelia / aurelia / packages / __tests__ / router / route-recognizer.spec.ts View on Github external
it('should distinguish between dynamic and static parts', function () {
    const sut = new RouteRecognizer();
    const similarRoute = { 'path': 'optionalToo/:id?', 'handler': { 'name': 'similar' }};
    sut.add([optionalRoute, similarRoute]);

    const result = sut.recognize('optionalToo');
    assert.strictEqual(result.length, 1, `result.length`);
    assert.strictEqual(result[0].handler.name, 'similar', `result[0].handler.name`);
  });
github aurelia / aurelia / packages / __tests__ / router / route-recognizer.spec.ts View on Github external
it('should reject default parameter values', function () {
    const sut = new RouteRecognizer();

    assert.throws(() => sut.add([{'path': 'user/:id=1', 'handler': {}}]), void 0, `() => sut.add([{'path': 'user/:id=1', 'handler': {}}])`);
  });
github aurelia / aurelia / packages / __tests__ / router / route-recognizer.spec.ts View on Github external
it('should find handlers by route name', function () {
    const sut = new RouteRecognizer();
    sut.add([staticRoute]);

    assert.strictEqual(sut.hasRoute('static'), true, `sut.hasRoute('static')`);
    assert.strictEqual(sut.handlersFor('static')[0].handler, staticRoute.handler, `sut.handlersFor('static')[0].handler`);
  });
github aurelia / aurelia / packages / __tests__ / router / route-recognizer.spec.ts View on Github external
xit('should reject unknown routes', function () {
    const sut = new RouteRecognizer();

    assert.strictEqual(sut.hasRoute('static'), false, `sut.hasRoute('static')`);
    assert.throws(() => sut.handlersFor('static'), void 0, `() => sut.handlersFor('static')`);
    assert.throws(() => sut.generate('static'), void 0, `() => sut.generate('static')`);
    assert.strictEqual(sut.recognize('/notfound'), undefined, `sut.recognize('/notfound')`);
  });
github aurelia / aurelia / packages / __tests__ / router / route-recognizer.spec.ts View on Github external
it('should find a handler by multiple names', function () {
    const sut = new RouteRecognizer();
    sut.add([multiNameRoute]);

    assert.strictEqual(
      sut.handlersFor('static-multiple')[0].handler,
      sut.handlersFor('static-multiple-alias')[0].handler
    );
  });
github aurelia / aurelia / packages / __tests__ / router / route-recognizer.spec.ts View on Github external
it('should distinguish between dynamic and static parts', function () {
    const sut = new RouteRecognizer();
    const similarRoute = { 'path': 'optionalToo/:id?', 'handler': { 'name': 'similar' }};
    sut.add([optionalRoute, similarRoute]);

    const result = sut.recognize('optionalToo');
    assert.strictEqual(result.length, 1, `result.length`);
    assert.strictEqual(result[0].handler.name, 'similar', `result[0].handler.name`);
  });
github aurelia / aurelia / packages / __tests__ / router / route-recognizer.spec.ts View on Github external
it('should require dynamic segment parameters when generating', function () {
    const sut = new RouteRecognizer();
    sut.add([dynamicRoute]);

    assert.throws(() => sut.generate('dynamic'), void 0, `() => sut.generate('dynamic')`);
    assert.throws(() => sut.generate('dynamic', {}), void 0, `() => sut.generate('dynamic', {})`);
    assert.throws(() => sut.generate('dynamic', { id: null }), void 0, `() => sut.generate('dynamic', { id: null })`);
  });