Skip to content

Commit

Permalink
fix: improve matcher routing for SEO URLs (#1387)
Browse files Browse the repository at this point in the history
* reordered check for routing matches to first check product routes then category routes and at the end content page routes (to be less eager to assume it is a content page)
* replace all occurences of object markers (pg, prd, ctg) in slug data instead of only the first (to prevent unintended object markers with multiple occurences)
* updated project configuration to consistently use the Angular 15 standard configuration of `ES2022` that includes `replaceAll`
- `replaceAll('pg', 'Pg')` could be replaced by `replace(/pg/g, 'Pg')`
  • Loading branch information
shauke committed Apr 3, 2023
1 parent f3ac967 commit afa4fab
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/app/core/utils/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export function sanitizeSlugData(slugData: string) {
.replace(/-+/g, '-')
.replace(/-+$/, '')
.toLowerCase()
.replace('pg', 'Pg')
.replace('prd', 'Prd')
.replace('ctg', 'Ctg') || ''
.replaceAll('pg', 'Pg')
.replaceAll('prd', 'Prd')
.replaceAll('ctg', 'Ctg') || ''
);
}
8 changes: 4 additions & 4 deletions src/app/pages/app-last-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import { matchContentRoute } from 'ish-core/routing/content-page/content-page.ro
import { matchProductRoute } from 'ish-core/routing/product/product.route';

const routes: Routes = [
{
matcher: matchContentRoute,
loadChildren: () => import('./content/content-page.module').then(m => m.ContentPageModule),
},
{
matcher: matchProductRoute,
loadChildren: () => import('./product/product-page.module').then(m => m.ProductPageModule),
Expand All @@ -19,6 +15,10 @@ const routes: Routes = [
matcher: matchCategoryRoute,
loadChildren: () => import('./category/category-page.module').then(m => m.CategoryPageModule),
},
{
matcher: matchContentRoute,
loadChildren: () => import('./content/content-page.module').then(m => m.ContentPageModule),
},
{
path: '**',
canActivate: [notFoundStatusGuard],
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"downlevelIteration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "CommonJS",
"module": "ES2022",
"moduleResolution": "node",
"importHelpers": true,
"target": "ES2022",
Expand All @@ -25,7 +25,7 @@
],
"swiper_angular": ["node_modules/swiper/angular"]
},
"lib": ["es2018", "dom"],
"lib": ["ES2022", "dom"],
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitAny": true,
Expand Down

0 comments on commit afa4fab

Please sign in to comment.