I'm trying to implement angular universal. But I want to limit SSR  only in  2 specific routes for the time being. 
The reasons are .
1) Universal is something still developing and causes some unexpected behaviors with @angular/flex-layout  and nested lazy loading
2) I don t need SEO on all pages
So i've tried something like this
app.get('/campaign/*/*', (req, res) => {
   res.render(join(DIST_FOLDER, 'browser', 'index.html'), { req });
});
app.get('/', (req, res) => {
   res.render(join(DIST_FOLDER, 'browser', 'index.html'), { req });
});
app.get('*', (req, res) => {
});
But when i try to navigate in page  /campaign/new-channel  pages reloads forever.
The expected behavior I expect is  the page to normally without any content be rendered . 
I suppose I have to do something different since node express should pass the handling of routing to angular .
Any idea how to implement this ?
The rest code of server.ts is copied from here https://github.com/angular/universal-starter/blob/master/server.ts
P.S There is this post on stackoverflow Angular universal rendering for some routes only but no solution is provided .So I made this one since I don't know if i m allowed to open new thread in answers
To enable SSR in Angular, Angular should be able to rendered in the server. To make it happen, Angular provides a special technology called Angular Universal.
A primary benefit for using Angular Universal is that it improves web crawler support for enhanced Search Engine Optimization (SEO). With traditional client-side rendered SPAs, anything that is not in that shell of an . html is all rendered by the JavaScript.
In a nutshell, Angular Universal is a Pre-Rendering solution for Angular. To understand what this means, let's remember that in a normal single page application, we usually bring the data to the client and then build the HTML that represents that data last second on the client side.
Finally  response.sendFile  is what I was searching for 
app.get('/campaign/new-channel', function (req, res) {
   res.sendFile(join(DIST_FOLDER, 'browser', 'index.html'));
});
What you want is just to return the index.html without any rendered content
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With