Customer account redirect to the orders , i want to redirect to the specific page

Short description of issue

Previous i uses legacy account for login , now i switch to the customer account. I added a button to say login, its redirect to the login .after that it is redirect to the orders. I want it to be specific page based on where the user click login button.

Reproduction steps

Just login, after successfully login,it redirect to the orders tabs.

Additional info

So is this a default behavior or we can change it from theme or somewhere else.

What type of topic is this

Troubleshooting
General discussion

1 Like

Hi there!

I recommend using {{ routes.storefront_login_url }} in your theme.

When you use this URL for your customer account login button, it will send the customer back to where they were when they pressed the login button once logged in :slight_smile:

More information here:

Let me know if you encounter any issues.

2 Likes

@Paige-Shopify Can you confirm if theres a way to do this on legacy customer accounts?

With legacy customer accounts, you can use the return_to form parameter on the login form. There is an example code snippet of how that is handled in our docs:

1 Like

That won’t work though because we’re already on the login page then. How will we know what page we’ve come from? For example I need to have a login button on a PDP and return to that product specifically after logging in.

Depends on where your customer_login form is located and submitted for legacy customer accounts.

If we take a leaf from the Horizon theme’s book and add a dropdown for customer login so customers can login from any page, then the return_to parameter can still be used with it set to request.path.

Just tested it out to see if any captcha issues get in the way, but seems to work well:

The login form is on the login page (/account/login), so unfortunately that wouldn’t work here as the client doesn’t want a popover.

Does the client want to log in from the customer account login page or the product page?

If the form is included on a product page, the approach I shared still works.

No, there is a login button in place of their add to cart button, which takes them to /account/login

Oh I see! Ok, that does make things complicated.

In that scenario you might have to use JS.
Session storage would work better than using History state I imagine.