Angular 角度4力导航与刷新

Angular 角度4力导航与刷新,angular,Angular,在我的一个组件中(它不是AppComponent) 我想先通过刷新整个应用程序来导航特定呼叫: this.router.navigate(['/en/homepage']) 我的AppComponent的构造函数中基本上有一个APP\u初始值设定项和一些动态路由设置,我希望在导航到指定的URL之前再次运行该代码。因此,我不是在寻找我所有的routerLink/router.navigate来刷新应用程序,只是一个特定的应用程序 由于我使用的是服务器端应用程序(带有universal),因此无法

在我的一个组件中(它不是
AppComponent

我想先通过刷新整个应用程序来导航特定呼叫:

this.router.navigate(['/en/homepage'])
我的
AppComponent
的构造函数中基本上有一个
APP\u初始值设定项和一些动态路由设置,我希望在导航到指定的URL之前再次运行该代码。因此,我不是在寻找我所有的routerLink/router.navigate来刷新应用程序,只是一个特定的应用程序

由于我使用的是服务器端应用程序(带有universal),因此无法使用
window.location.href

TL;博士 您只需使用
location.href
(而不是您提到的
window.location.href


更多资讯: 位置在Typescript SDK的lib.dom中定义

下面是相应的Typescript接口,它应该提示您可以执行的操作:

interface Location {
    hash: string;
    host: string;
    hostname: string;
    href: string;
    readonly origin: string;
    pathname: string;
    port: string;
    protocol: string;
    search: string;
    assign(url: string): void;
    reload(forcedReload?: boolean): void;
    replace(url: string): void;
    toString(): string;
}

没有测试这个,但是作为一种解决方法,可能可以工作:this.router.navigate(['/?redirectUrl=/en/homepage'])然后将调用根路由(以及AppComponent),在那里您可以检查这个查询字符串参数(订阅ActiveRoute的参数)'redirectUrl',并执行新的导航。
interface Location {
    hash: string;
    host: string;
    hostname: string;
    href: string;
    readonly origin: string;
    pathname: string;
    port: string;
    protocol: string;
    search: string;
    assign(url: string): void;
    reload(forcedReload?: boolean): void;
    replace(url: string): void;
    toString(): string;
}