Introduction
In this project, you will learn how to fix a bug in the vue-router library by modifying the cleanPath function. The vue-router library is a popular routing solution for Vue.js applications, and it's important to ensure that it works correctly, especially for edge cases like paths starting with multiple slashes.
👀 Preview

🎯 Tasks
In this project, you will learn:
- Understand the issue with the
cleanPathfunction in thevue-routerlibrary - Install the necessary dependencies for the project
- Locate and modify the
cleanPathfunction to fix the issue - Rebuild the project with the updated
cleanPathfunction - Test the fix to ensure that the issue is resolved
🏆 Achievements
After completing this project, you will be able to:
- Identify and diagnose issues in third-party libraries
- Modify and update the code in a third-party library to fix a bug
- Rebuild and release a project with the updated code
- Test the fix to ensure that the issue is resolved
Set Up the Project Structure
In this step, you will set up the project structure and learn about the issue in the vue-router library and how to fix it.
The vue-router library has a bug in version 3.5.2 where a path starting with multiple slashes (///) may actually redirect to another domain. This is because the cleanPath function in the library only replaces two slashes, instead of all multiple slashes.
To fix this issue, you will need to modify the cleanPath function in the vue-router-3.5.2/src/util/path.js file.
To get started, look at the directory structure of the files on the left as follows:
├── vue-router-3.5.2
├── vue.js
└── index.html
Click on Go Live button in the bottom right corner of WebIDE, to run the project.
Open "Web 8080" on the top of the VM and refresh it manually, the effect should be as follows:

Copy the address in the image above to open a new window in your browser and click on the "Go to Foo" button and the page will jump to a Google page.

Fix the cleanPath Function
Open the
vue-router-3.5.2/src/util/path.jsfile.Locate the
cleanPathfunction:export function cleanPath(path: string): string { return path.replace(/\/\//g, "/"); }Update the
cleanPathfunction to replace all multiple slashes with a single slash:export function cleanPath(path: string): string { return path.replace(/\/+/g, '/'); }The
/\/+/gregular expression will match one or more consecutive slashes and replace them with a single slash.
Rebuild and Test the Project
In the terminal, navigate to the
vue-router-3.5.2directory.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 all dependencies have been successfully installed, run the command
npm run buildto rebuild and release the project with the updatedcleanPathfunction.Go back to the web page and refresh the page.
Click the "Go to Foo" button, and you should see that the page no longer redirects to a Google page, but instead stays on the local application.

Congratulations! You have successfully fixed the issue in the vue-router library by updating the cleanPath function.
Summary
Congratulations! You have completed this project. You can practice more labs in LabEx to improve your skills.



