Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,44 @@ function findVueRouter(vueRoot) {
}

function walkRouter(rootNode, callback) {
const stack = [{node: rootNode, path: ''}];
const stack = [{ node: rootNode, path: '' }];

while (stack.length) {
const { node, path} = stack.pop();
const { node, path } = stack.pop();

if (node && typeof node === 'object') {
if (Array.isArray(node)) {
for (const key in node) {
stack.push({node: node[key], path: mergePath(path, node[key].path)})
// (修复代码1)Ensure node[key] is an object and has a path property before pushing to stack
if (node[key] && typeof node[key] === 'object' && 'path' in node[key]) {
stack.push({ node: node[key], path: mergePath(path, node[key].path) });
}
}
} else if (node.hasOwnProperty("children")) {
stack.push({node: node.children, path: path});
stack.push({ node: node.children, path: path });
}
}

callback(path, node);
// Only call callback if node is defined and has a path property
if (node && node.path !== undefined) {
callback(path, node);
}
}
}

function mergePath(parent, path) {
// (修复代码2)Check if path is undefined or null before processing
if (typeof path === 'undefined' || path === null) {
return parent ? parent + '/' : '';
}

// 报错位置
if (path.indexOf(parent) === 0) {
return path
return path;
}

return (parent ? parent + '/' : '') + path
return (parent ? parent + '/' : '') + path;
}

function main() {
const vueRoot = findVueRoot(document.body);
if (!vueRoot) {
Expand Down Expand Up @@ -99,5 +110,4 @@ function main() {

return routers
}

console.table(main())