gpt4 book ai didi

javascript - Angular 通用和翻译

转载 作者:行者123 更新时间:2023-12-02 23:18:13 24 4
gpt4 key购买 nike

添加延迟加载后,我遇到了闪烁问题(使用通用模块在服务器端渲染后重绘 View )我已经通过initialNavigation修复了这个问题:“启用”并且它修复了闪烁但是这个选项破坏了 url 中带有 lang 前缀的所有路由所有像“/ru/user/deposit”这样的路由都会像主页一样呈现,而无需在服务器端进行翻译。没有前缀的路由在服务器端渲染得很好。

app.routering.module.ts

const routes: Routes = [

{ path: '', redirectTo: 'sport/esports', pathMatch: 'full' },
{
path: 'sport/esports',
loadChildren: './modules/matches/matches.module#MatchesModule',
},
{
path: 'blog',
loadChildren: './modules/blog/blog.module#BlogModule',
},
{
path: 'static',
loadChildren: './modules/static/static.module#StaticModule',
},
{
path: 'slots',
loadChildren: './modules/slots/slots.module#SlotsModule',
canActivate: [FreeLootGuard]
},
{
path: 'user',
loadChildren: './layouts/user-layout/user-layout.module#UserLayoutModule'
},
{
path: '**', redirectTo: '/sport/esports', pathMatch: 'full'
}
];
@NgModule({
imports: [
LocalizeRouterModule.forRoot(routes, {
parser: {
provide: LocalizeParser,
useFactory: (translate, location, settings) =>
new ManualParserLoader(translate, location, settings, ['en', 'ru', 'pl', 'es', 'de', 'tr', 'fil', 'pt', 'zh'], ''),
deps: [TranslateService, Location, LocalizeRouterSettings]
},
alwaysSetPrefix: false,
useCachedLang: false
}),
RouterModule.forRoot(routes, {initialNavigation: 'enabled'}),
],
exports: [RouterModule]
});

app.server.module.ts

export function translateFactory(transferState: TransferState) {
return new TranslateServerLoader('/assets/i18n/', '.json', transferState);
}

export function localizeLoaderFactory(translate: TranslateService, location: Location, settings: LocalizeRouterSettings) {
return new LocalizeServerLoader(translate, location, settings);
}

if (environment.sentryUrl) {
SentryNode.init({
dsn: environment.sentryUrl
});
}

@Injectable()
export class SentryNodeErrorHandler implements ErrorHandler {
constructor() {}
handleError(error) {
let message: any;
let err: any;
if (environment.sentryUrl) {
if (error.status) {
if (error && error.error && error.error.messages && error.error.messages.length) {
message = error.error.messages[0];
} else {
message = error.message || 'Not found';
}
} else if (error.rejection) {
message = error.toString();
} else {
message = error;
}
err = typeof message === 'string' ? new Error(message) : error;
SentryNode.captureException(error.originalError || err);
} else {
console.error(error);
}
}
}

@NgModule({
imports: [
AppModule,
ServerModule,
ModuleMapLoaderModule,
ServerTransferStateModule,
TranslateModule.forRoot({
loader:{
provide: TranslateLoader,
useFactory: translateFactory,
deps: [TransferState]
}
})
],
providers: [
{ provide: ErrorHandler, useClass: SentryNodeErrorHandler },
{ provide: CookieService, useClass: CookieBackendService },
// Add universal-only providers here
],
bootstrap: [ AppComponent ],
})
export class AppServerModule {}

最佳答案

关于javascript - Angular 通用和翻译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57080540/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com