通过ConfigureRouter测试添加路由。我们如何看待NavModel? [英] Test the addition of a route via ConfigureRouter. How do we see the NavModel?
本文介绍了通过ConfigureRouter测试添加路由。我们如何看待NavModel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在以下测试中, router.navigation
属性的长度为零。我们如何访问我们的路线 NavModel
?
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();
});
});
});
将路由器
写入控制台显示:
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: ...
}
}
}
推荐答案
我认为您只需要将 nav:true
属性添加到您在 mapRoute $ c $中映射的路线c>。
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...
});
这篇关于通过ConfigureRouter测试添加路由。我们如何看待NavModel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文