Git Product home page Git Product logo

Comments (4)

teddygunawan avatar teddygunawan commented on July 18, 2024 2

@samk-dev
Hello! I think you misunderstand the usage of sendRedirect in this context. In this case, because u call it using the fetch method on the client side, what happens is that the nitro server will send 302 alongside a location response header, which will cause the browser to try the fetch request on the redirected url instead. You can look at the network tab of developer console to confirm this.

In another context, if for example you are trying to open that url instead, which in this case is /api/force-redirect, you can see that the page is properly routed to /login, this is also because of the header and status code. This is simply how the browser works.

as for the reason that it returns the index page, you can see from the sendRedirect spec that it mentions

it adds the location header to the response and sets the status code to 302 by default.
In the body, it sends a simple HTML page with a meta refresh tag to redirect the client in case the headers are ignored.

If you wish to do client side redirect, to change the way you code the redirection, e.g. return the url for the client to manually redirect to.

Hope this helps!

from nuxt.

samk-dev avatar samk-dev commented on July 18, 2024 1

@teddygunawan Thanks a lot for the great explanation

from nuxt.

stackblitz avatar stackblitz commented on July 18, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

from nuxt.

manniL avatar manniL commented on July 18, 2024

As @teddygunawan said!

from nuxt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.