提交 a5e6b1c1 编写于 作者: 璃白.'s avatar 璃白. 🌻

feat:添加重定向插件

上级 49824049
此差异已折叠。
class SidebarRedirect {
menuList = [];
constructor() {
this.init();
}
init() {
this.reWriteUrlFunction();
window.addEventListener("pushState", e => {
setTimeout(() => {
const list = this.getMenuList();
this.redirect(list);
});
});
window.onload = () => {
const list = this.getMenuList();
this.redirect(list);
};
}
getMenuList() {
const menuList = [...document.querySelectorAll(".sidebar .sidebar-link")];
return menuList;
}
redirect(list) {
const len = list.length;
if (len === 1) {
console.log(list[0]);
location.replace(list[0].href);
}
}
reWriteUrlFunction() {
const _historyWrap = function (type) {
const orig = history[type];
const e = new Event(type);
return function () {
const rv = orig.apply(this, arguments);
e.arguments = arguments;
window.dispatchEvent(e);
return rv;
};
};
history.pushState = _historyWrap("pushState");
history.replaceState = _historyWrap("replaceState");
}
}
export default new SidebarRedirect();
const { path } = require("@vuepress/shared-utils");
/**
* @type {import('@vuepress/types').Plugin}
*/
module.exports = {
enhanceAppFiles: path.resolve(__dirname, "enhanceAppFile.js")
};
......@@ -4,6 +4,7 @@
"docs:build": "vuepress build docs"
},
"devDependencies": {
"@vuepress/plugin-back-to-top": "^1.9.7",
"vuepress": "^1.9.7",
"vuepress-plugin-autometa": "^0.1.13"
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册