解决这个问题的方法是在应用程序的入口处设置initialNavigation
配置项为false
,并在组件中手动执行初始化导航。
例如,假设我们的根组件是AppComponent
,我们可以在其构造函数中导航到当前 URL,以确保初始化导航已完成:
import { Component } from '@angular/core';
import { Router } from '@angular/router';
@Component({
selector: 'app-root',
template: ` `
})
export class AppComponent {
constructor(private router: Router) {
this.router.navigate([this.router.url], { replaceUrl: true });
}
}
然后,在我们的应用程序模块中,我们需要将initialNavigation
设置为false
:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
@NgModule({
imports: [
BrowserModule.withServerTransition({ appId: 'my-app' }),
RouterModule.forRoot([{
path: '**',
component: AppComponent
}], {
initialNavigation: false
})
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule { }
现在,我们的 Angular 15 SSR 应用程序应该能够在移动 IOS 13 浏览器中正常工作了。