Introduction
In this project, you will learn how to fix a bug in the vue-router-2.7.0 library related to handling null values in the query parameter.
👀 Preview

🎯 Tasks
In this project, you will learn:
- How to locate and understand the
isObjectEqualfunction in thevue-router-2.7.0/src/util/route.jsfile. - How to fix the
isObjectEqualfunction to correctly handlenullvalues. - How to rebuild and release the
vue-router-2.7.0project with the fixed function. - How to test the fix by checking the browser console for the absence of the previous error messages.
🏆 Achievements
After completing this project, you will be able to:
- Identify and fix a bug in a third-party library.
- Work with the
vue-router-2.7.0library and understand its internal functions. - Rebuild and release a project after making code changes.
- Test the fix by checking the browser console for error messages.
Fix the isObjectEqual Function
To get started, look at the directory structure of the files on the left as follows:
├── vue-router-2.7.0
├── vue.min.js
└── index.html
Click on Go Live button in the bottom right corner of WebIDE, to run the project.
Next, open "Web 8080" on the top of the VM and refresh it manually, click "test" and open the Console option in the browser console, you will see two error messages, they are TypeError: Cannot convert undefined or null to object and Uncaught TypeError: Cannot convert undefined or null to object.

In this step, you will learn how to fix the isObjectEqual function in the vue-router-2.7.0/src/util/route.js file to handle null values correctly.
- Open the
vue-router-2.7.0/src/util/route.jsfile. - Locate the
isObjectEqualfunction:
function isObjectEqual(a = {}, b = {}): boolean {
const aKeys = Object.keys(a);
const bKeys = Object.keys(b);
if (aKeys.length !== bKeys.length) {
return false;
}
return aKeys.every((key) => {
const aVal = a[key];
const bVal = b[key];
// check nested equality
if (typeof aVal === "object" && typeof bVal === "object") {
return isObjectEqual(aVal, bVal);
}
return String(aVal) === String(bVal);
});
}
- Update the function to handle
nullvalues correctly:
function isObjectEqual(a = {}, b = {}): boolean {
if (!a || !b) return a === b;
const aKeys = Object.keys(a);
const bKeys = Object.keys(b);
if (aKeys.length !== bKeys.length) {
return false;
}
return aKeys.every((key) => {
const aVal = a[key];
const bVal = b[key];
// check nested equality
if (typeof aVal === "object" && typeof bVal === "object") {
return isObjectEqual(aVal, bVal);
}
return String(aVal) === String(bVal);
});
}
The changes are:
- Added a condition to check if
aorbisnullorundefined. If either isnullorundefined, the function will returna === b. - This ensures that the function correctly handles
nullvalues in thequeryparameter.
Rebuild and Test the Project
In this step, you will rebuild and test the vue-router-2.7.0 project after fixing the isObjectEqual function.
- In the terminal, navigate to the
vue-router-2.7.0directory. - Run the command
npm installto install the dependencies. This process might take a while, please be patient. (If it gets stuck for a long time, please pressCtrl+Cto terminate the process and then run this command again.) - After the installation is complete, run the command
npm run buildto rebuild and release the project. This will generate the updatedvue-router-2.7.0library with the fixedisObjectEqualfunction. - Go back to the web page and refresh the page.
- Click on "test" and open the console in the
Consoletab to check, you will not see the above error message anymore.
If the error messages are gone, the fix is successful. You have completed the project!

Summary
Congratulations! You have completed this project. You can practice more labs in LabEx to improve your skills.



