Creation:2026-01-22Last update:2026-01-22
Reference this doc to your favorite AI assistantChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Implemented custom URL rewrites"v8.0.022/01/2026
The content of this page was translated using an AI.
See the last version of the original content in EnglishEdit this doc
If you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy
Copy doc Markdown to clipboard
Documentation: getCanonicalPath function in intlayer
Description
The getCanonicalPath function resolves a localised 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's language.
Key Features:
- Supports dynamic route parameters using the
[param]syntax. - Matches localised paths against custom rewrite rules defined in your configuration.
- Returns the original path if no matching rewrite rule is found.
Function Signature
Parameters
Required Parameters
localizedPath: string- Description: The localised path as seen in the browser (e.g.,
/a-propos). - Type:
string - Required: Yes
- Description: The localised 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:
Usage with Dynamic Routes
Manual Rewrite Rules
You can also pass manual rewrite rules to the function:
Related Functions
getLocalizedPath: Resolves a canonical path into its localised equivalent.getLocalizedUrl: Generates a fully localised URL (including protocol, host, and locale prefix).