מחבר:
הפנו את עוזר ה-AI המועדף עליכם למסמך הזהChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
היסטוריית גרסאות
- "Implement custom URL rewrites"v8.0.022.1.2026
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתעריכת המסמך הזה
אם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודנוצר:2026-01-22עדכון אחרון:2026-09-27
העתקה
העתקת ה-Markdown של המסמך ללוח
Documentation: getCanonicalPath Function in intlayer
Description
The getCanonicalPath function resolves a localized URL path (e.g., /a-propos) back to its internal canonical application path (e.g., /about). This is essential for routers to match the correct internal route regardless of the URL language.
Key Features:
- Supports dynamic route parameters using the
[param]syntax. - Matches localized paths against custom rewrite rules defined in your configuration.
- Returns the original path if no matching rewrite rule is found.
Function Signature
typescript
העתקת קוד
העתקת הקוד ללוח
Parameters
Required Parameters
localizedPath: string- Description: The localized path as seen in the browser (e.g.,
/a-propos). - Type:
string - Required: Yes
- Description: The localized path as seen in the browser (e.g.,
locale: Locales- Description: The locale used for the path being resolved.
- Type:
Locales - Required: Yes
Optional Parameters
rewriteRules?: RoutingConfig['rewrite']- Description: An object defining custom rewrite rules. If not provided, it defaults to the
routing.rewriteproperty from your project's configuration. - Type:
RoutingConfig['rewrite'] - Default:
configuration.routing.rewrite
- Description: An object defining custom rewrite rules. If not provided, it defaults to the
Returns
- Type:
string - Description: The internal canonical path.
Example Usage
Basic Usage (With Configuration)
If you have configured custom rewrites in your intlayer.config.ts:
typescript
העתקת קוד
העתקת הקוד ללוח
Usage with Dynamic Routes
typescript
העתקת קוד
העתקת הקוד ללוח
Manual Rewrite Rules
You can also pass manual rewrite rules to the function:
typescript
העתקת קוד
העתקת הקוד ללוח
