Open lee-wilkins opened 5 years ago
Same issue here, I temporarily removed the data.
I just tested with data: { skipRouteLocalization: true }, it causes the same issue.
I have the same problem and I have been able to fix it by making a quick fix in parseSegmentValue function in the localize-router.service.ts file.
The culprit is the condition else if (snapshot.routeConfig.data)
. When the route has a data
key, snapshot.routeConfig.data
returns both the object with the localizeRouter
and the data
key content.
To avoid this, I add a condition to check if there is a localizeRouter
in the data (else if (snapshot.routeConfig.data && snapshot.routeConfig.data.localizeRouter)
Here is the whole method. Please check my fork for the fix : https://github.com/cariboufute/localize-router
// src/localize-router.service.ts
// ...
/**
* Extracts new segment value based on routeConfig and url
* @param snapshot
* @returns {string}
*/
private parseSegmentValue(snapshot: ActivatedRouteSnapshot): string {
if (snapshot.routeConfig) {
if (snapshot.routeConfig.path === '**') {
return this.parser.translateRoute(snapshot.url
.filter((segment: UrlSegment) => segment.path)
.map((segment: UrlSegment) => segment.path)
.join('/'));
} else if (snapshot.routeConfig.data && snapshot.routeConfig.data.localizeRouter) {
const subPathSegments = snapshot.routeConfig.data.localizeRouter.path.split('/');
return subPathSegments
.map((s: string, i: number) => s.indexOf(':') === 0 ?
snapshot.url[i].path :
this.parser.translateRoute(s))
.join('/');
}
}
return '';
}
Description
In order to switch the navbar color on the homepage I have the following situation in my app-routing.module
in external-routing.module:
Note the deep empty route.
The page loads the first time fine. However if i switch the language on the homepage i get:
core.js:14597 ERROR TypeError: Cannot read property 'path' of undefined
Inspecting the error shows that in the code a data attribute causes the path to be split by "/", which obviously cannot happen in my case as i have an empty path.
localize-router.service.js:117
I can fix this by re-routing my homepage to /home as such, but this is not ideal:
🌍 Your Environment
**Angular Version: 7.1.1
Localize Router Version: