帮忙网页的SEO,就是header里插入meta的keyword description 与title
我的路由格式
简单而又粗暴的插进去
router.beforeEach((to, from, next) => {
const oldKey = document.getElementsByName('keywords').item(0);
if (oldKey) {
oldKey.remove();
}
const oldDes = document.getElementsByName('description').item(0);
if (oldDes) {
oldDes.remove();
}
if (to.meta.title) {
document.title = to.meta.title;
}
if (to.meta.content) {
const head = document.getElementsByTagName('head');
const meta0 = document.createElement('meta');
meta0.name = 'keywords';
meta0.content = to.meta.content.keywords;
const meta1 = document.createElement('meta');
meta1.name = 'description';
meta1.content = to.meta.content.description;
head[0].appendChild(meta0);
head[0].appendChild(meta1);
}
next();
});
结果