Skip to content

Commit

Permalink
fix translate path with redirect function
Browse files Browse the repository at this point in the history
  • Loading branch information
gilsdav committed Jun 17, 2024
1 parent 1cd85c9 commit 9e10508
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-translate-router/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 9 additions & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } } },

{
Expand Down
2 changes: 1 addition & 1 deletion src/assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 9e10508

Please sign in to comment.