最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

在Node中下载PDF文件并重定向到前端React

IT培训 admin 6浏览 0评论

在Node中下载PDF文件并重定向到前端React

你能帮我下一个Node.js中的文件并将其重定向到前端吗?我正在使用MERN堆栈(Mongo,Express,React,Node)。

在使用Google Auth进行身份验证后,我想在Node中下载文件,然后我想重定向该页面。

router.get(
    '/auth/google/callback',
    passportGoogle.authenticate('google', {
        failureRedirect: '/',
    }),
    (req, res) => {
        try {
          var file = 'resume.pdf';
          res.download(file, (err => {
          if (err) {
                console.log(err)
          } else {
                window.location.href = '/';
          }
        }));
    }
);

我尝试了这段代码,但下载后并没有将页面重定向到前端。

回答如下:
   (req, res) => {
        try {
          var file = 'resume.pdf';
          res.download(file, (error => {
          if (!error) {
              window.location.replace("http://stackoverflow");
          } else {
                console.log(error)
          }
        }));
    } 
            catch {
                    console.log(error)
    }

在Node中下载PDF文件并重定向到前端React

你能帮我下一个Node.js中的文件并将其重定向到前端吗?我正在使用MERN堆栈(Mongo,Express,React,Node)。

在使用Google Auth进行身份验证后,我想在Node中下载文件,然后我想重定向该页面。

router.get(
    '/auth/google/callback',
    passportGoogle.authenticate('google', {
        failureRedirect: '/',
    }),
    (req, res) => {
        try {
          var file = 'resume.pdf';
          res.download(file, (err => {
          if (err) {
                console.log(err)
          } else {
                window.location.href = '/';
          }
        }));
    }
);

我尝试了这段代码,但下载后并没有将页面重定向到前端。

回答如下:
   (req, res) => {
        try {
          var file = 'resume.pdf';
          res.download(file, (error => {
          if (!error) {
              window.location.replace("http://stackoverflow");
          } else {
                console.log(error)
          }
        }));
    } 
            catch {
                    console.log(error)
    }
发布评论

评论列表 (0)

  1. 暂无评论