Answer the question
In order to leave comments, you need to log in
Angular2 how to do server side rendering?
Somehow everything is cloudy and incomprehensible. There is a project on the angular/universal github. But I'm not so versed in Javascript to understand what exactly it solves.
The task is simple as a boot - when a visitor follows an external link to a single-page web application, the server renders a page that would also set the state of the application. And then the visitor is already working with a one-page rendering in the browser.
SEOs want the server to give the link not the bootstrap of the application, but the content equivalent to what the visitor will receive by clicking on a specific link in the one-page.
If the second angular is not able, are there any javascript libraries that can?
Thank you.
Answer the question
In order to leave comments, you need to log in
https://github.com/angular/universal-starter
All answers are in src/server.ts file. The essence is this:
1) create an express application
2) set up the processing of .html files on the angular renderer from universe
app.engine('.html', expressEngine);
app.set('views', __dirname);
app.set('view engine', 'html');
function ngApp(req, res) {
let baseUrl = '/';
let url = req.originalUrl || '/';
res.render('index', {
directives: [ Html ],
...
}
}
app.use(express.static(root, {index: false}));
// Routes with html5pushstate
app.use('/', ngApp);
app.use('/about', ngApp);
app.use('/home', ngApp);
// Server
app.listen(3000, () => {
console.log('Listen on http://localhost:3000');
});
https://vinaygopinath.me/blog/tech/seo-in-angular2...
Try this
Here is a step-by-step and detailed description of how to enable rendering to the server with Angular Universal (with a working example on github)
Angular Universal: Server-side generation implementation ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question