@tanstack/react-router 1.153.2 → 1.154.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1588,6 +1588,53 @@ The \`RouterOptions\` type accepts an object with the following properties and m
1588
1588
  - Defaults to \`/\`
1589
1589
  - The basepath for the entire router. This is useful for mounting a router instance at a subpath.
1590
1590
 
1591
+ ### \`rewrite\` property
1592
+
1593
+ - Type: \`LocationRewrite\`
1594
+ - Optional
1595
+ - Configures bidirectional URL transformation between the browser URL and the router's internal URL.
1596
+ - See the [URL Rewrites guide](../../guide/url-rewrites.md) for detailed usage and patterns.
1597
+
1598
+ The \`LocationRewrite\` type has the following shape:
1599
+
1600
+ \`\`\`tsx
1601
+ type LocationRewrite = {
1602
+ input?: LocationRewriteFunction
1603
+ output?: LocationRewriteFunction
1604
+ }
1605
+
1606
+ type LocationRewriteFunction = (opts: { url: URL }) => undefined | string | URL
1607
+ \`\`\`
1608
+
1609
+ - \`input\`: Transforms the URL before the router interprets it (browser → router)
1610
+ - \`output\`: Transforms the URL before it's written to browser history (router → browser)
1611
+
1612
+ **Example**
1613
+
1614
+ \`\`\`tsx
1615
+ import { createRouter } from '@tanstack/react-router'
1616
+
1617
+ const router = createRouter({
1618
+ routeTree,
1619
+ rewrite: {
1620
+ input: ({ url }) => {
1621
+ // Strip locale prefix: /en/about → /about
1622
+ if (url.pathname.startsWith('/en')) {
1623
+ url.pathname = url.pathname.replace(/^\/en/, '') || '/'
1624
+ }
1625
+ return url
1626
+ },
1627
+ output: ({ url }) => {
1628
+ // Add locale prefix: /about → /en/about
1629
+ url.pathname = \`/en\${url.pathname === '/' ? '' : url.pathname}\`
1630
+ return url
1631
+ },
1632
+ },
1633
+ })
1634
+ \`\`\`
1635
+
1636
+ When both \`basepath\` and \`rewrite\` are configured, they are automatically composed. The basepath rewrite runs first on input (stripping the basepath) and last on output (adding it back).
1637
+
1591
1638
  ### \`context\` property
1592
1639
 
1593
1640
  - Type: \`any\`