This article will show you how to return members to the page they were viewing before being asked to sign up or login. This is especially handy if you have a content or functionality that is partially gated (like a blog or comment sections).
data-ms-redirect="current-url"
Use the attribute data-ms-redirect="current-url"
to save the current URL. The next time that visitor goes to sign up or login they will be returned to the page.
You can place the attribute anywhere, but we recommend placing it on your signup and login links.
Considerations
- Does not work with onboarding UI. It will override your default signup redirect.
- This will override default redirects and plan level redirects.
Keywords:
Stay on page, stay-on page, override redirect, after login, after signup, save page, save url, current url,
Comments
14 comments
This did not work for us.
Mark Burlinson Do you have a redirect hard-coded into your signup/login form by chance?
I just did some testing and this feature is working as expected for me. It you can share a video or read-only link that would be super helpful to debug 🙏
Duncan Hamra Does this data-ms-redirect attribute work for URL's where there's gated content?
For context:
- User clicks on link from email to go specific page
- Page happens to be gated content (user is not logged in)
- MS kicks user to log-in page (normal behavior)
- On log in event --> page redirects from plan level redirects back to original URL they were 'kicked out of'.
Thanks a mill!
Joe
++ update ++
I did add this attribute to the main nav of my web app. (This is a common element across my Member area.)
This did not work. I understand it should likely be a form element.
I did try it on my login button on my login *page* (not modal), but obviously that just grabbed the current URL (which was "log-in") which directed me back to itself.
I have 8+ pages on my web app, sometimes I need to send users straight a specific page (once they log in). I might just hard code this as a cookie and do some logic here if this isn't native to MS. Thanks!
There's no way for it to remember the first page if that page is gated. This attribute only "remembers" the current URL if it is clicked by the member.
Thank you for the update! I just tested the attribute on my own site, and it all appears to be working correctly. If the member clicks a link or section with the attribute they will be returned to the page on login.
Thanks Duncan from Memberstack! I appreciate the response.
Could I use this in the following situation:
1. A user is taken to a pricing page where they select a recurring payment plan
2. Upon submitting the pricing form, they're are taken to a signup form where they can either create an account or log in
3. If the user already has an account (for a different product), they can log in and be taken straight to the Stripe payment form.
I'm scratching my head on this one as it seems like it should be pretty straightforward, but this solution seems like it would just keep them on the signup/login form.
Drew Birnie Thanks for asking!
Does that make more sense? No worries if not, just let me know and I'll record a video.
Duncan from Memberstack
What if the user has an account and is NOT logged in? I'm having issues with that scenario. This is what happens in that case right now:
1. They select a pricing plan on a pricing page and click on "checkout"
2. From there, they are directed to the signup form
3. They click on "Already have an account? Log in." and are taken to the login form where they can successfully log in
4. Once they do, they're taken to their member dashboard <<< This is where the problem is. I need them to be taken to the Stripe payment form for whichever recurring plan they selected.
Ahh right! Thank you for clarifying.
Have you seen this MemberScript yet? If you add it to your site I believe it will fix your issue. https://docs.memberstack.com/hc/en-us/community/posts/18410652090139-How-to-Launch-Checkout-after-Login
Hey there, It's not 100% clear where I should add this code.
I'm using the Memberstack modals.
Can this be anywhere on the page?
Or does it need to be on the button that triggers the modal?
I recommend adding it to the same button that triggers the modal.
That worked perfectly - thanks Duncan from Memberstack
Hey Duncan! Love Memberstack!
Is there any way to only redirect back to this page on login?
I’d like to still use Onboarding UI for sign up.
Thanks!
Hey Braden, thanks for the kind words 🙏
I see why you'd want that, sadly this attribute does not allow for it. That said, I think it could be possible with custom code. First idea that comes to mind. It would essentially turn any page into your onboarding page until the onboarding from is complete.
If you give this info to Rey (the AI) it can help you create the custom code.
Please sign in to leave a comment.