Test the addition of a route via ConfigureRouter. How do we see the NavModel?

旧巷老猫 提交于 2020-01-05 05:01:17

问题


In the following test, the router.navigation property has a length of zero. How do we access our routes NavModel?

import { Container } from "aurelia-framework";
import { RouterConfiguration, Router } from "aurelia-router";

describe("the RouterConfiguration", function () {

    let container: Container = new Container();
    let routerConfiguration: RouterConfiguration = container.get(RouterConfiguration);
    let router: Router = container.get(Router);

    it("adds a route with a NavModel", function (done) {

        routerConfiguration.mapRoute({
            moduleId: "test",
            name: "test",
            navigationStrategy: (instruction) => {
                instruction.config.moduleId = "something";
            },
            route: "test",
        });

        let configureRouter: Promise<void> = router.configure(routerConfiguration);

        configureRouter.then(function () {

            router.baseUrl = "foobar";
            router.refreshNavigation();

            expect(router.isConfigured).toBe(true);
            expect(router.routes.length).toBe(1);
            expect(router.navigation.length).toBe(1); // fails
            expect(router.hasRoute("test")).toBe(true);
            done();
        });
    });
});

Writing the router to the console displays this:

Router
{
    parent: null, 
    options: Object{}, 
    container: undefined, 
    history: undefined, 
    viewPorts: Object{}, 
    routes: [
        Object
        {
            moduleId: ..., 
            name: ..., 
            navigationStrategy: ..., 
            route: ..., 
            settings: ..., 
            navModel: ...
        }
    ], 
    baseUrl: '', 
    isConfigured: true, 
    isNavigating: false, 
    navigation: [], 
    currentInstruction: null, 
    _fallbackOrder: 100,
    _recognizer: RouteRecognizer
    {
        rootState: State {charSpec: ..., nextStates: ...}, 
        names: Object{test: ...}
    }, 
    _childRecognizer: RouteRecognizer
    {
        rootState: State{charSpec: ..., nextStates: ...}, 
        names: Object{test: ...}
    }, 
    _resolveConfiguredPromise: function (value) { ... },
    _configuredPromise: Promise
    {
        _bitField: 33554432, 
        _fulfillmentHandler0: undefined, 
        _rejectionHandler0: undefined, 
        _promise0: undefined, 
        _receiver0: undefined, 
        _trace: CapturedTrace
        {
            _parent: ..., 
            _promisesCreated: ..., 
            _length: ..., 
            _promiseCreated: ...
        }
    }
}

回答1:


I think you just need to add the nav: true property to the route you are mapping in mapRoute.

routerConfiguration.mapRoute({
    moduleId: "test",
    name: "test",
    navigationStrategy: (instruction) => {
      instruction.config.moduleId = "something";
    },
    route: "test",
    nav: true // I want the route to be included in the nav model...
  });


来源:https://stackoverflow.com/questions/38905525/test-the-addition-of-a-route-via-configurerouter-how-do-we-see-the-navmodel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!