小编Pie*_*ool的帖子

Angular2 Window.Location.HREF UNIT测试

我正在尝试运行component testfor Angular2,我必须检查该函数,该函数调用对允许本地运行程序启动的URL的调用。该功能正在运行,但是可以breaking the unit tests

单元测试失败是因为 Some of your tests did a full page reload!

有没有一种方法可以捕获window.location.href呼叫obtaining the called URL并阻止其刷新。

unit-testing typescript angular

5
推荐指数
0
解决办法
808
查看次数

初始化前从 REST 服务的角度加载路由

我正在研究 Angular 8 从 REST 服务动态创建路由的可能性。这个想法是用户可以通过在网页上路由来创建应该可以访问的页面。

我已经看到了动态添加路由的选项,但是我希望在应用程序的其余部分之前加载路由,以便当用户访问时:'website/generatedPage' 路由在应用程序完全加载之前就位。

在应用程序继续路由选项之前,如何确保来自 REST 服务的路由就位?

以下代码将路由添加到后期:

    constructor(
    private sitemapService: SitemapService,
    private router: Router
) {
    this.sitemapService.getSiteMap().then(result => {
        result.forEach(sitemapItem => {
            this.router.config.push({ path: sitemapItem.pageName, component: PageComponent });
        });
    });
}
Run Code Online (Sandbox Code Playgroud)

使用此代码,您可以在加载应用程序时导航到该页面,但是,当您直接请求路由时,它尚未加载。

先感谢您!

rest routing routeconfig angular

5
推荐指数
1
解决办法
1382
查看次数

标签 统计

angular ×2

rest ×1

routeconfig ×1

routing ×1

typescript ×1

unit-testing ×1