/    Sign up×
Community /Pin to ProfileBookmark

how do i send a router redirect from express to react?

this is one of the things ive tried but it doesnt work. I do get redirected if going straight to the /test in the url(localhost:3001/test) and if sending a json object from express instead of the redirect, then I do get the JSON object to the react app so nothing is wrong with the connection between them.
Please can you help me make it work?

[CODE]
// express on port 3001
router.get(‘/test’, (req, res) => {
res.redirect(‘/login’)
});

// react on port 3000
fetch(‘/test’)
[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@sagarchavadaMay 22.2019 — You have to export this route file using Module.exports = { }; and require this route or module into the react file.

[upl-image-preview url=https://www.webdeveloper.com/assets/files/2019-05-22/1558500538-431347-22.png]

[upl-image-preview url=https://www.webdeveloper.com/assets/files/2019-05-22/1558500538-480412-11.png]
×

Success!

Help @bbq1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 3.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 10 SATS,
)...