> For the complete documentation index, see [llms.txt](https://kotus.gitbook.io/saas-starter-kit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kotus.gitbook.io/saas-starter-kit/helpers/toasts/getredirectpathwithtoasterror.md).

# getRedirectPathWithToastError

## getRedirectPathWithToastError

### Description

The `getRedirectPathWithToastError` function generates a redirect path with URL parameters to display a toast.

### Signature

```typescript
function getRedirectPathWithToastError(path: string, message: string, title: string | null = null): string;
```

### Parameters

* `path`: The path to redirect to.
* `message`: The message to display in the toast.
* `title`: The title of the toast.

### Example Usage

```typescript
// I strongly recommend using useTranslations.
const t = useTranslations();
const redirectPath = getRedirectPathWithToastError('/dashboard', t('your.message'), t('your.title'));
```

### Returns

The generated redirect path with URL parameters to display the toast.

## How It Works

1. **Retrieving URL Parameters**: The component uses `useSearchParams` to get the URL parameters.
2. **Displaying the Toast**: If a message is present in the parameters, a toast is displayed with the appropriate title and variant.
3. **Cleaning Up URL Parameters**: The parameters used for the toast are removed from the URL to prevent the toast from being displayed again on page refresh.

### Example of Redirect with Toast

Suppose you have a server-side action that redirects the user to a page with an error message:

```typescript
const redirectPath = getRedirectPathWithToastError('/dashboard', 'Something went wrong', 'Error');
router.push(redirectPath);
```

This will redirect the user to `/dashboard?tmessage=Something%20went%20wrong&ttitle=Error&tvariant=destructive`. When the `/dashboard` page loads, the `Toaster` component will display a toast with the message "Access denied" and the title "Error".

### Conclusion

By using the `getRedirectPathWithToastError` function and the `Toaster` component, you can easily display toasts based on URL parameters, which is particularly useful for informing users of the results of server-side actions.
