# Redirect when overriding a route

**URL:** https://community.forestadmin.com/t/redirect-when-overriding-a-route/7456
**Category:** Help me!
**Created:** [September 17, 2024, 10:35am UTC](https://community.forestadmin.com/t/redirect-when-overriding-a-route/7456 "2024-09-17T10:35:39Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![MarcoGarcia](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/marcogarcia/32/2715_2.png) [@MarcoGarcia](https://community.forestadmin.com/u/MarcoGarcia)
#### Post date: [September 17, 2024, 10:35am UTC](https://community.forestadmin.com/t/redirect-when-overriding-a-route/7456/1 "2024-09-17T10:35:39Z")

</div>

## Feature(s) impacted

Hello,  
I want to duplicate a record under certain conditions in my route `router.put('/:collection/:recordId')`.  
When those conditions are met, after the duplication, I want to redirect to the newly created record.

## Observed behavior

I can’t find a way to do the redirection.

The only thing that seems to work is

```javascript
return response.status(statusThatIsNot200).send('Some random message')

```

But the express redirection is not working.  
Types let me think that it is possible but I’m getting this error `An error occurred when trying to edit ${collection}: unexpected error`.

 ![Capture d’écran 2024-09-17 à 12.23.18](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/b/bd35336c4f2be57811257f5b8b51be21d8504ee1.png)

You can reproduce it with

```javascript
router.put(`/${collection}/:recordId`, permissionMiddlewareCreator.update(), async (req, res, next) => {
  return res.redirect(`https://app.forestadmin.com/${projectName}/${envName}/${teamName}/data/${collection}/index/record/${collection}/${anotherId}/details`)
})

```

## Expected behavior

I expect to be able to use some functions of the express response or to have an alternative to redirect to a given url.

## Failure Logs

There is no failure logs.  
Only the badge in the app with the error `An error occurred when trying to edit ${collection}: unexpected error`.

## Context

- Project name: mytraiteur
- Team name: Operations
- Environment name: Development | marco2
- Agent technology: Legacy version: Express
- Agent (forest package) name & version: forest-express-sequelize@9.3.9
- Database type: MYSQL
- Recent changes made on your end if any: none

---

<div class="post-metadata">

### Author: ![Alban\_Bertolini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/alban_bertolini/32/1077_2.png) [@Alban\_Bertolini](https://community.forestadmin.com/u/Alban_Bertolini)
#### Post date: [September 17, 2024, 11:34am UTC](https://community.forestadmin.com/t/redirect-when-overriding-a-route/7456/2 "2024-09-17T11:34:02Z")

</div>

Hello,  
To find an alternative, why do you want to redirect the user after an update?

Forestadmin does not support the redirection on the detail view because the frontend application needs to receive the update result 😕

If you really want to do a redirection, you can probably use a [smart action](https://docs.forestadmin.com/documentation/reference-guide/actions/create-and-manage-smart-actions/use-a-smart-action-form) to update record and do a redirection after the execution. But the edition is not from the detail view.

🙏

---

<div class="post-metadata">

### Author: ![MarcoGarcia](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/marcogarcia/32/2715_2.png) [@MarcoGarcia](https://community.forestadmin.com/u/MarcoGarcia)
#### Post date: [September 17, 2024, 12:18pm UTC](https://community.forestadmin.com/t/redirect-when-overriding-a-route/7456/3 "2024-09-17T12:18:23Z")

</div>

Because I want to duplicate the record under certain conditions in my route `put` instead of updating the current record.  
So I want the user to see the new record because the old one hasn’t been updated at all.

For my usecase, it’s when I update a product’s price, I want to disable the old one and create a new one with the new price.  
The only problem I’m facing is the redirection.

I thought of using a smart action but it’s not as simple as updating a record for our users.

I can return the old one to avoid the error.  
But if I do that, is there a way to change the success message ?  
And maybe put a link in it ?

---

<div class="post-metadata">

### Author: ![Alban\_Bertolini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/alban_bertolini/32/1077_2.png) [@Alban\_Bertolini](https://community.forestadmin.com/u/Alban_Bertolini)
#### Post date: [September 17, 2024, 12:33pm UTC](https://community.forestadmin.com/t/redirect-when-overriding-a-route/7456/4 "2024-09-17T12:33:52Z")

</div>

Ok I understand your needs. You want to have an history of your price.

Unfortunately is not possible. Smart Action is developed in part to support this case. You can create a smart action: `Edit Price` with a dedicated form and set the price as readonly in the layout. With this trick, customers can’t edit the price but they can always edit others records. If they want to edit the price, they can use the action 😕 🙏

---

<div class="post-metadata">

### Author: ![MarcoGarcia](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/marcogarcia/32/2715_2.png) [@MarcoGarcia](https://community.forestadmin.com/u/MarcoGarcia)
#### Post date: [September 17, 2024, 12:54pm UTC](https://community.forestadmin.com/t/redirect-when-overriding-a-route/7456/5 "2024-09-17T12:54:36Z")

</div>

Ok thanks.

Just a last question, is there a way to do this in the latest version of the Node.js forestadmin agent ?

---

<div class="post-metadata">

### Author: ![Alban\_Bertolini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/alban_bertolini/32/1077_2.png) [@Alban\_Bertolini](https://community.forestadmin.com/u/Alban_Bertolini)
#### Post date: [September 17, 2024, 2:47pm UTC](https://community.forestadmin.com/t/redirect-when-overriding-a-route/7456/6 "2024-09-17T14:47:36Z")

</div>

> is there a way to do this in the latest version of the Node.js forestadmin agent ?

Unfortunately, no, the limitation comes from the designed Forestadmin workflow, not the agent but I still recommend using this version 🙂
