SEO with express.js and prerender-node

橙三吉。 提交于 2019-12-23 05:17:13

问题


Front-end:

I have SPA client website that uses own routing system. For instance it has route http://localhost:8080/about

Back-end:

I'm using prerender-node on express.js server (runs on port 3001) to prerender static html for crawler bots:

app.use(require('prerender-node')
    .set('prerenderServiceUrl', 'http://localhost:3000/')
    .set('afterRender', function (err, req, prerender_res) {
        console.log('URL: ', req.url); // here I see: "/about?_escaped_fragment_="
    }));

my express routing looks like this:

router.get('*', function (req, res, next) {
    res.sendFile(path.resolve('../frontend/dist/index.html'));
});

Problem:

The problem is that if I send http://localhost:3001/about?_escaped_fragment_= to the server as a response I get static index.html home page (but I wanted to prerender about section).

As I understand prerender-node middleware doesn't know how to navigate to /about section and prerenders always home page.

Question:

How to prerender the actual about page of my SPA according to a link?

来源:https://stackoverflow.com/questions/35856296/seo-with-express-js-and-prerender-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!