在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)
}