egg.js重定向问题
发布于 6 年前 作者 dmodaii 8157 次浏览 来自 问答
  • 使用egg.js开发
  • 在post请求的controller中准备重定向到这个url
      const setLoginState = await this.service.portal.portal.getLoginState()
      this.ctx.redirect(setLoginState);
  • 前端的console 重定向为什么会产生options请求方式 image.png

  • 看了使用的lib koa中的response的redirect源码没错啊

redirect(url, alt) {
    // location
    if ('back' == url) url = this.ctx.get('Referrer') || alt || '/';
    this.set('Location', url);

    // status
    if (!statuses.redirect[this.status]) this.status = 302;

    // html
    if (this.ctx.accepts('html')) {
      url = escape(url);
      this.type = 'text/html; charset=utf-8';
      this.body = `Redirecting to <a href="${url}">${url}</a>.`;
      return;
    }

    // text
    this.type = 'text/plain; charset=utf-8';
    this.body = `Redirecting to ${url}.`;
  },

各位在post请求中怎么重定向的啊

3 回复

你这个是不是ajax 请求的后台 我怎么看到了vue

ajax 请求 redirect 有什么用。

@JacksonTian 谢谢大佬 1、我已经返回url给vue前端, 让前端自己跳转了 2、或者让前端get方式我这个node接口来跳转

回到顶部