diff --git a/README.md b/README.md index e47292a..2d20db5 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Based on and extension of [ngx-translate](https://github.com/ngx-translate/core) | 15.1 | 6.1.0 | 2.0.0 | active | minimum angular 15.1.0 | | 16 | 7.0.0 | 2.0.0 | active | minimum angular 16 | | 17 | 7.1.0 | 2.0.0 | active | optional standalone API | -| 18 | 7.2.0 | 2.0.0 | active | | +| 18 | 7.2.1 | 2.0.0 | active | | Demo project can be found under sub folder `src`. diff --git a/projects/ngx-translate-router/package.json b/projects/ngx-translate-router/package.json index 6a095d4..3f641b6 100644 --- a/projects/ngx-translate-router/package.json +++ b/projects/ngx-translate-router/package.json @@ -1,6 +1,6 @@ { "name": "@gilsdav/ngx-translate-router", - "version": "7.2.0", + "version": "7.2.1", "homepage": "https://github.com/gilsdav/ngx-translate-router#readme", "license" : "MIT", "author": { diff --git a/projects/ngx-translate-router/src/lib/localize-router.parser.ts b/projects/ngx-translate-router/src/lib/localize-router.parser.ts index 7a8082b..cd9fa5a 100755 --- a/projects/ngx-translate-router/src/lib/localize-router.parser.ts +++ b/projects/ngx-translate-router/src/lib/localize-router.parser.ts @@ -171,10 +171,7 @@ export abstract class LocalizeParser { const skipRouteLocalization = (route.data && route.data['skipRouteLocalization']); const localizeRedirection = !skipRouteLocalization || skipRouteLocalization['localizeRedirectTo']; - if (route.redirectTo && localizeRedirection) { - if (typeof route.redirectTo === 'function') { - return; - } + if (route.redirectTo && localizeRedirection && !(typeof route.redirectTo === 'function')) { const prefixLang = route.redirectTo.indexOf('/') === 0 || isRootTree; this._translateProperty(route, 'redirectTo', prefixLang); } diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 43f20f5..c254801 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -83,6 +83,15 @@ export const routes: Routes = [ return localizeRouterService.translateRoute('/home') as string; } }, + { + path: '!conditionalRedirectTo', redirectTo: ({ queryParams }) => { + const localizeRouterService = inject(LocalizeRouterService); + if (queryParams['redirect']) { + return localizeRouterService.translateRoute('/test') as string; + } + return localizeRouterService.translateRoute('/home') as string; + } + }, { path: 'toredirect', redirectTo: '/home', data: { skipRouteLocalization: { localizeRedirectTo: true } } }, { diff --git a/src/assets/locales/en.json b/src/assets/locales/en.json index 5ce25f1..c9a7f69 100644 --- a/src/assets/locales/en.json +++ b/src/assets/locales/en.json @@ -7,7 +7,7 @@ "ROUTES.sub": "sub", "ROUTES.map": "map", "ROUTES.matcher": "mymatcher", - "ROUTES.conditionalRedirectTo": "conditionalRedirectTo", + "ROUTES.conditionalRedirectTo": "trConditionalRedirectTo", "CHANGE_LANGUAGE": "Change language", "GO_HOME": "Go home", "DEFAULT_TITLE": "My title",