Skip to content

Commit

Permalink
docs: Return getPathname where relevant
Browse files Browse the repository at this point in the history
  • Loading branch information
amannn committed Nov 18, 2024
1 parent 140ef46 commit 1ff5003
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const routing = defineRouting({

// Lightweight wrappers around Next.js' navigation APIs
// that will consider the routing configuration
export const {Link, redirect, usePathname, useRouter} =
export const {Link, redirect, usePathname, useRouter, getPathname} =
createNavigation(routing);
```

Expand Down
13 changes: 7 additions & 6 deletions docs/src/pages/docs/routing/navigation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {defineRouting} from 'next-intl/routing';

export const routing = defineRouting(/* ... */);

export const {Link, redirect, usePathname, useRouter} =
export const {Link, redirect, usePathname, useRouter, getPathname} =
createNavigation(routing);
```

Expand All @@ -32,10 +32,11 @@ In case you're building an app where locales can be added and removed at runtime
```tsx filename="routing.ts"
import {createNavigation} from 'next-intl/navigation';

export const {Link, redirect, usePathname, useRouter} = createNavigation({
// ... potentially other routing
// config, but no `locales` ...
});
export const {Link, redirect, usePathname, useRouter, getPathname} =
createNavigation({
// ... potentially other routing
// config, but no `locales` ...
});
```

Note however that the `locales` argument for the middleware is still mandatory. If you need to fetch the available locales at runtime, you can provide the routing configuration for the middleware [dynamically per request](/docs/routing/middleware#composing-other-middlewares).
Expand Down Expand Up @@ -324,7 +325,7 @@ function UserProfile({userId}: {userId?: string}) {
To work around this limitation, you can add an explicit type annotation to the `redirect` function:

```tsx filename="routing.ts"
const {redirect: _redirect} = createNavigation(routing);
const {/* ..., */ redirect: _redirect} = createNavigation(routing);

// Enable type narrowing after calling `redirect`
export const redirect: typeof _redirect = _redirect;
Expand Down

0 comments on commit 1ff5003

Please sign in to comment.