diff --git a/packages/theme/src/services/i18n/i18n-url.guard.ts b/packages/theme/src/services/i18n/i18n-url.guard.ts index bf1113ee0..21c4b6345 100644 --- a/packages/theme/src/services/i18n/i18n-url.guard.ts +++ b/packages/theme/src/services/i18n/i18n-url.guard.ts @@ -25,7 +25,9 @@ export class AlainI18NGuardService { } /** - * Simple 路由守卫, [ACL Document](https://ng-alain.com/auth/guard). + * Internationalization guard, automatically recognizes the language in Url and triggers the `ALAIN_I18N_TOKEN.use` method + * + * 国际化守卫,自动识别Url中的语言,并触发 `ALAIN_I18N_TOKEN.use` 方法 * * ```ts * data: { @@ -37,7 +39,9 @@ export class AlainI18NGuardService { export const alainI18nCanActivate: CanActivateFn = childRoute => inject(AlainI18NGuardService).process(childRoute); /** - * Simple 路由守卫, [ACL Document](https://ng-alain.com/auth/guard). + * Internationalization guard, automatically recognizes the language in Url and triggers the `ALAIN_I18N_TOKEN.use` method + * + * 国际化守卫,自动识别Url中的语言,并触发 `ALAIN_I18N_TOKEN.use` 方法 * * ```ts * data: { diff --git a/src/app/layout/header/header.component.ts b/src/app/layout/header/header.component.ts index 8a09b6be1..2adfaadd8 100644 --- a/src/app/layout/header/header.component.ts +++ b/src/app/layout/header/header.component.ts @@ -8,7 +8,7 @@ import { copy } from '@delon/util/browser'; import type { NzSafeAny } from 'ng-zorro-antd/core/types'; import { NzMessageService } from 'ng-zorro-antd/message'; -import { I18NService, MobileService } from '@core'; +import { I18NService, LangType, MobileService } from '@core'; import { MetaSearchGroupItem } from '../../interfaces'; import { LayoutComponent } from '../layout.component'; @@ -100,6 +100,7 @@ export class HeaderComponent implements AfterViewInit { } langChange(language: 'en' | 'zh'): void { + this.i18n.use(language as LangType, {}, false); this.router.navigateByUrl(`${this.i18n.getRealUrl(this.router.url)}/${language}`).then(() => { this.layout.render = false; setTimeout(() => { diff --git a/src/app/routes/routes.module.ts b/src/app/routes/routes.module.ts index a1c1bae90..a3758e365 100644 --- a/src/app/routes/routes.module.ts +++ b/src/app/routes/routes.module.ts @@ -1,8 +1,6 @@ import { NgModule } from '@angular/core'; import { Route, RouterModule } from '@angular/router'; -import { alainI18nCanActivate } from '@delon/theme'; - import { NotFoundComponent } from './404/404.component'; import { HomeComponent } from './home/home.component'; import { LayoutComponent } from '../layout/layout.component'; @@ -14,7 +12,6 @@ const routes: Route[] = [ { path: '', component: LayoutComponent, - canActivateChild: [alainI18nCanActivate], children: [ { path: '', redirectTo: 'en', pathMatch: 'full' }, { path: ':lang', component: HomeComponent, data: { titleI18n: 'slogan' } },