问题
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.
回答1:
Your 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 completed.
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 component. Please check the requests being made by the new component 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.
回答2:
'cause Link
component 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.com/index', '_self')
- Use
<a href="http://your.new.domain.com/index">
回答3:
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
来源:https://stackoverflow.com/questions/46726120/the-page-is-being-unloaded-error