Y
Y
Yuri Matyukhin2014-11-02 23:10:18
Search Engine Optimization
Yuri Matyukhin, 2014-11-02 23:10:18

What is the error in setting up redirects in express for seo-friendly spa (angular)?

Good afternoon, I'm trying to optimize for SPA search on angular js (angular full stack).
As a guide, I used an article found on Google www.algoworks.com/blog/a-developers-guide-to-perfo... Snapshots
were created for the article, but the link with ?_escaped_fragment_= does not give me a snapshot.
This code was supposed to give the desired snapshot, but for some reason it does not work:

module.exports = function(app) {

  // In our app.js configuration
  app.use(function(req, res, next) {
    var fragment = req.query._escaped_fragment_;
    if (!fragment) return next();

    if (fragment === "" || fragment === "/")
      fragment = "/index.html";

    if (fragment.charAt(0) !== "/")
      fragment = '/' + fragment;

    if (fragment.indexOf('.html') == -1) fragment += ".html";

    fragment = fragment.replace(/\//g, 'prefix-');

    try {
      var file = __dirname + "assets/snapshots/snapshot_" + fragment;
      res.sendfile(file);
    } catch (err) {
      res.send(404);
    }
  });


  app.get(function (req, res) {
    res.send('Welcome');
  })

  // All undefined asset or api routes should return a 404
  app.route('/:url(api|auth|components|app|bower_components|assets)/*')
    .get(errors[404]);

  // All other routes should redirect to the index.html
  app.route('/*')
    .get(function(req, res) {
      res.sendfile(app.get('appPath') + '/index.html');
    });
};

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question