Routing
Answered
West African Lion posted this in #help-forum
West African LionOP
Hello hello, I created a form for adding a transaction and since I can use it for editing it as well, I couldn't figure out how to redirect the user to the same form with the specific action he selected without creating two different routes for each, add & edit, since there's a seperate button for each action.
Answered by B33fb0n3
of course you can also have only the (in my example)
pageId route and then pass a default id in it. Check inside that page if it's the default id. If it's the default id, then it's the "create" action and if it's a different id, then it's a "save" action. Like that you have only one route, to handle both10 Replies
@West African Lion Hello hello, I created a form for adding a transaction and since I can use it for editing it as well, I couldn't figure out how to redirect the user to the same form with the specific action he selected without creating two different routes for each, add & edit, since there's a seperate button for each action.
you can create a "EditForm" component and pass the action via props down to the button. When there is an id, then it's the save action. Else it's the create action
West African LionOP
but I wanna have only one form, a transaction form that could handle both
I won't have a simple model where I can pass the action, I wanna redirect the user to a seperate route where they can create or edit
@West African Lion I won't have a simple model where I can pass the action, I wanna redirect the user to a seperate route where they can create or edit
yes, you will have both: (see attached)
Multiple routes, only one form and the action passed as props down to the form
Multiple routes, only one form and the action passed as props down to the form
West African LionOP
but there's no way I can have one route and one form?
@West African Lion but there's no way I can have one route and one form?
of course you can also have only the (in my example)
pageId route and then pass a default id in it. Check inside that page if it's the default id. If it's the default id, then it's the "create" action and if it's a different id, then it's a "save" action. Like that you have only one route, to handle bothAnswer
West African LionOP
oh yeah that makes total sense. Thank you.
I have another issue related to tailwind with shadcn
can I describe it here?
I have another issue related to tailwind with shadcn
can I describe it here?
Each thread is limited to one topic. So open another thread and whenever I am able to help you, I will help you
West African LionOP
alright thanks