I was working with a NodeJS-ReactJS Isomorphic App, and when I click on a Link
I'm getting an error saying
Uncaught (in promise) Error: Request has been terminated
Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.
The first two reasons (offline and CORS) I heard about. What is the the page is being unloaded
error means? How it may cause the browser not navigating to need.
I was working with a NodeJS-ReactJS Isomorphic App, and when I click on a Link
I'm getting an error saying
Uncaught (in promise) Error: Request has been terminated
Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.
The first two reasons (offline and CORS) I heard about. What is the the page is being unloaded
error means? How it may cause the browser not navigating to need.
-
Is your link pointing to an external domain ? If so then better use
a
tag. – Fawaz Commented Oct 13, 2017 at 13:00 -
I am using
a
tag insideLink
ponent. – Asim K T Commented Oct 25, 2017 at 6:21 - why would you do that! Use any one of them at a time. – Fawaz Commented Oct 25, 2017 at 12:02
- I don't understand. It's a react ponent. This is how a ponent works..! – Asim K T Commented Oct 30, 2017 at 6:29
3 Answers
Reset to default 4 +50Your Error is
Uncaught (in promise) Error: Request has been terminated
This error is caused when the request in the promise is terminated before it is resolved or rejected. This can happen if (Possible causes
)
the network is offline
: There is a network failure and the connection to the url using which the request was being processed is lost.Origin is not allowed by Access-Control-Allow-Origin
: The request is rejected due to absence of proper CORS headers.the page is being unloaded
: The page making the request is closed before the request pleted.
Of the above reasons, the most probable cause relevant to your case would be either 1 or 2, since you get the error on clicking a Link
to navigate to a ponent. Please check the requests being made by the new ponent that is being loaded using the Link
.
Edit: If you look at the error message screen shot, it clearly states that the error occured at line no. 73194 of app.js at PromiseRequest in node_modules/superagent/lib/client.js.Request.crossDomainError. So the reason for your error is a CORS error which is described in number 2 above.
'cause Link
ponent is using Location.push
to do the redirection, while Location.push
method cannot redirect to another domain.
So my solutions are:
- Use
window.open('http://your.new.domain./index', '_self')
- Use
<a href="http://your.new.domain./index">
It seems you have not enabled the cors in your node server. Suggested Steps:
npm install cors
use it in app.js (node server)
.
var cors = require('cors');
var app = express();
app.use(cors()); //Enable CORS