问题
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
回答1:
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
来源:https://stackoverflow.com/questions/49325054/angular-universal-only-to-specific-routes