Online store customer login redirects
You can configure where customers are redirected after they log in to their account on your store. For example, you might want to redirect customers to the page they were on when they logged in, or a specific product collection.
In this tutorial, you'll learn how to configure custom redirects in your theme.
Anchor to ResourcesResources
Use routes
object to manage login redirection.
Anchor to Redirecting to customer accountsRedirecting to customer accounts
Before you edit your theme code, review the considerations for customizing your theme to prevent any unintended changes to your store.
In Liquid, the routes
object can be used to direct customers to customer accounts, where they can view their order history and track current orders:
routes.account_login_url
: Takes customers to the login screen and then to the order index page after a successful loginroutes.account_url
: Takes customers to customer accounts order index page directly
If you need to append a path (such as for an account extension, tab, or subpage) to routes.account_url
,
be aware that this URL may sometimes contain query parameters (for example, after a successful login).
To ensure your generated links remain valid, always split routes.account_url
on the ?
character
before appending your extension, then re-attach any query parameters at the end.
Example:
/sections/header.liquid
This approach always produces a valid link, regardless of whether routes.account_url contains
query parameters.
Anchor to Modify your login links to redirect to the order index pageModify your login links to redirect to the order index page
If your store's theme supports a customer account login link, then the following is an example of the default route on the header.liquid
page:
/sections/header.liquid
If your theme doesn't display a login link in your theme header, then you can add a customer account login link to your theme with the following Liquid code:
/sections/header.liquid
Anchor to Link directly to customer account pagesLink directly to customer account pages
Create direct links to redirect customers to specific customer account pages, such as their Profile page:
/sections/header.liquid
Link to a customer account full-page extension with the following Liquid code:
/sections/header.liquid
Anchor to Direct customers back to the online storeDirect customers back to the online store
Direct your customers back to the online store after successful login by editing your theme code to use the routes.storefront_login_url
object. Once logged in, the customer will be taken back to the page where the login originated. For example, if a customer is on the Catalogs page and clicks on the login link, they will be taken back to Catalogs after a successful login.
The following example demonstrates how you can modify the customer account login link with the storefront_login_url
route. In this example, after a customer logs in, they will be taken back to the storefront. If they click on the login link again, they will be taken to customer accounts:
/sections/header.liquid
You can also add the route to any login URL on your storefront with the following Liquid code:
/sections/header.liquid
If you choose to direct customers back to the online store after login by replacing the default login link route, we recommend you use another link on your theme that navigates customers to their accounts/orders.
Anchor to Direct customers back to another page on the online storeDirect customers back to another page on the online store
You can redirect customers to any page on your online store using the /customer_authentication/login
path with a return_to
parameter.
For example, to redirect customers to your Contact page after login, use this Liquid code:
/sections/header.liquid
The return_to
parameter will only work with relative URLs.