New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NUXT redirect before html rendering #2287

Closed
adnanmokhtar opened this Issue Nov 30, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@adnanmokhtar
Copy link

adnanmokhtar commented Nov 30, 2017

i want to redirect to another domain if user comes from mobile when i type the url in browser before any html rendering.

but some html header and footer appear before redirect happen

how to fix that

This question is available on Nuxt.js community (#c2002)
@InstanceOfMichael

This comment has been minimized.

Copy link

InstanceOfMichael commented Nov 30, 2017

You should be able to come up with a solution after reading these. There's multiple ways to address this, such in a component, in the vue-router, or in a middleware.

https://router.vuejs.org/en/advanced/navigation-guards.html
#112 (comment)
https://nuxtjs.org/api/configuration-router/#extendroutes
https://nuxtjs.org/guide/routing#middleware

Another option is to check in the root component's beforeMount function and redirect using:

if (!isMobile && window.location.origin === "mobile.yoururl.com") {
    window.location = "http://www.yoururl.com";
}
@adnanmokhtar

This comment has been minimized.

Copy link

adnanmokhtar commented Nov 30, 2017

it work fine if i use navigation the redirect happen before rendering

but if i refresh the page or enter from url the redirect happen after some of html appear in the page

@clarkdo

This comment has been minimized.

Copy link
Member

clarkdo commented Dec 11, 2017

redirect wii support external link in both server and client side in next release.

@clarkdo clarkdo referenced this issue Dec 11, 2017

Merged

feat: allow redirect to external url #2265

3 of 3 tasks complete

@clarkdo clarkdo closed this Dec 11, 2017

@lock

This comment has been minimized.

Copy link

lock bot commented Nov 2, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 2, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.