Ad

Is There A Correct Way To Allow Google To Read Angular 2 Content For SEO?

- 1 answer

I have an Angular 2 application which is publicly visible. When I log in to Google Webmaster Tools and request to render the page, I can see that it is just seeing the loading indicator and none of the content. Is there a recommended approach for allowing the contents of the site to be indexed?

I am hosting on an Apache server.

Ad

Answer

I think the recommended way is to render the page on server side, with angular-universal, here is a working version

https://github.com/angular/universal-starter/tree/angular-connect

something like this:

    import * as express from 'express';
    import {ng2engine} from 'angular2-universal-preview';

    // Angular 2
    import {App} from './src/app';

    let app = express();

    // Express View
    app.engine('.ng2.html', ng2engine);
    app.set('views', __dirname);
    app.set('view engine', 'ng2.html');


    // static files
    app.use(express.static(__dirname));


    app.use('/', (req, res) => {
      res.render('index', { App });
    });



    app.listen(3000, () => {
      console.log('Listen on http://localhost:3000');
    });
Ad
source: stackoverflow.com
Ad