You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aio/content/guide/universal.md
+5-20Lines changed: 5 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -279,24 +279,9 @@ So, you don't need to do anything to make relative URLs work on the server.
279
279
280
280
If, for some reason, you are not using an `@nguniversal/*-engine` package, you may need to handle it yourself.
281
281
282
-
One solution would be to provide the full URL to your application on the server (e.g. as a server-side only extra provider) and write an interceptor that can retrieve this value and prepend it to the request URL.
283
-
How to provide the full URL to requests depends on what you are using to render the app on the server-side and is outside the scope of this guide.
282
+
There are several ways to achieve that.
283
+
The recommended solution, which is also the least intrusive as it does not require any changes to the app, is to pass the full request URL to the `options` argument of [renderModule()](api/platform-server/renderModule) or [renderModuleFactory()](api/platform-server/renderModuleFactory) (depending on what you use to render `AppServerModule` on the server).
284
+
Here, "request URL" refers to the URL of the request as a response to which the app is being rendered on the server.
285
+
For example, if the client requested `https://my-server.com/dashboard` and you are rendering the app on the server to respond to that request, `options.url` should be set to `https://my-server.com/dashboard`.
284
286
285
-
This is half of the work.
286
-
The other half is using the provided full URL in the app.
287
-
This can be achieved by creating an [HttpInterceptor](api/common/http/HttpInterceptor).
This interceptor needs to be provided to the app on the server only, which can be done by adding it to the providers array of `AppServerModule`.
295
-
296
-
<code-example
297
-
header="src/app/app.server.module.ts"
298
-
path="universal/src/app/app.server.module.ts"
299
-
region="absolute-url-interceptor">
300
-
</code-example>
301
-
302
-
Now, on every HTTP request made on the server, this interceptor will fire and replace the request URL with the absolute URL using the provided `fullUrl`.
287
+
Now, on every HTTP request made as part of rendering the app on the server, Angular will be able to correctly resolve the request URL to an absolute URL, using the provided `options.url`.
0 commit comments