最近做项目的时候,被要求做seo,由于项目已经开发完毕,且只需首页做seo,所以考虑再三,决定用prerender-spa-plugin结合vue-meta-info来实现首页的seo。
如果你的页面是动态的,比如通过v-for或v-if等来动态渲染的dom,则不适合此方法,可以考虑官方的SSR。
代码已更新到github,点击查看
npm install prerender-spa-plugin vue-meta-info --save
cnpm install prerender-spa-plugin vue-meta-info --save
const PrerenderSpaPlugin = require(‘prerender-spa-plugin‘)
new PrerenderSpaPlugin(
//将渲染的文件放到dist目录下
path.join(__dirname, ‘../dist‘),
//需要预渲染的路由信息
[ ‘/index‘,‘/about‘ ],
{
//在一定时间后再捕获页面信息,使得页面数据信息加载完成
captureAfterTime: 50000,
//忽略打包错误
ignoreJSErrors: true,
phantomOptions: ‘--web-security=false‘,
maxAttempts: 10,
},
)
至此,你可以打包试试,如果打包后的文件包含index和about两个文件,表明成功。
但是运行打包的文件,右键查看网页源代码,你会发现,index和about这两个seo的文件信息是一样的,如果你也是这样的情况,别急,把你的路由模式换成"history"模式。
重新打包,运行打包文件,查看源代码,发现内容不一样了,至此才算成功。
但是会出现一个隐形的问题,当你打包后的文件部署到线上时,刷新页面就会404了。这时需要后端配置一下,后端配置
vue-meta-info的具体使用看这里 vue-meta-info
http://www.xxdshop.cn
http://www.aivvei.cn
http://www.carload.cn
http://www.zoenuu.cn
http://www.dunnuu.cn
http://www.geguni.cn
http://www.sujugo.cn
http://www.fireladyfor.cn
http://www.wookongg.cn
http://market.szonline.net/amaz/11198.html
http://market.szonline.net/amaz/11197.html
http://market.szonline.net/amaz/11196.html
http://market.szonline.net/amaz/11195.html
http://market.szonline.net/amaz/11194.html
http://market.szonline.net/amaz/11193.html
http://market.szonline.net/amaz/11192.html
http://market.szonline.net/amaz/11191.html
http://market.szonline.net/amaz/11190.html
http://market.szonline.net/amaz/11189.html
http://market.szonline.net/amaz/11188.html
http://market.szonline.net/amaz/11187.html
http://market.szonline.net/amaz/11186.html
http://market.szonline.net/amaz/11185.html
http://market.szonline.net/amaz/11184.html
http://market.szonline.net/amaz/11183.html
http://market.szonline.net/amaz/11182.html
http://market.szonline.net/amaz/11181.html
http://market.szonline.net/amaz/11180.html
http://market.szonline.net/amaz/11179.html
http://market.szonline.net/amaz/11178.html
http://market.szonline.net/amaz/11177.html
http://market.szonline.net/amaz/11176.html
http://market.szonline.net/amaz/11175.html
http://market.szonline.net/amaz/11174.html
http://market.szonline.net/amaz/11173.html
http://market.szonline.net/amaz/11171.html
http://market.szonline.net/amaz/11170.html
http://market.szonline.net/amaz/11169.html
http://market.szonline.net/amaz/11168.html
http://market.szonline.net/amaz/11167.html
http://market.szonline.net/amaz/11166.html
http://market.szonline.net/amaz/11165.html
http://market.szonline.net/amaz/11164.html
http://market.szonline.net/amaz/11163.html
http://market.szonline.net/amaz/11162.html
http://market.szonline.net/amaz/11161.html
http://market.szonline.net/amaz/11160.html
http://market.szonline.net/amaz/11159.html
http://market.szonline.net/amaz/11158.html
http://market.szonline.net/amaz/11157.html
http://market.szonline.net/amaz/11156.html
http://market.szonline.net/amaz/11154.html
http://market.szonline.net/amaz/11153.html
http://market.szonline.net/amaz/11152.html
http://market.szonline.net/amaz/11151.html
原文:https://www.cnblogs.com/zjw2004112/p/11556043.html