Introduction
In this project, you will learn how to fix a bug in the Vue Router v2.5.2 where the beforeRouteUpdate next() function is triggered too early when revisiting a route in an "out-in" transition.
👀 Preview

🎯 Tasks
In this project, you will learn:
- How to locate and understand the issue in the
vue-router-2.5.2/src/components/view.jsfile - How to fix the issue by updating the
data.registerRouteInstancefunction - How to rebuild the
vue-router-2.5.2project with the fix - How to test the fix to ensure the issue is resolved
🏆 Achievements
After completing this project, you will be able to:
- Identify and fix issues in the Vue Router library
- Rebuild a project after making code changes
- Test and verify the fix to ensure it resolves the issue
Fixing the Issue
To get started, look at the directory structure of the files on the left as follows:
├── vue-router-2.5.2
├── vue2.2.6.js
└── index.html
Click on Go Live button in the bottom right corner of WebIDE, to run the project.
Next, open "Web 8080" at the top of the VM and refresh it manually to see the page effect as described below:
- When you click "to /", the page will display "This is A".
- When you click "to /b", the page will display "This is B".
- When you click "to /" again, the page will display "This is".

In this step, you will fix the issue in the vue-router-2.5.2/src/components/view.js file.
Open the
vue-router-2.5.2/src/components/view.jsfile.Locate the line 53 of the file, which is the
data.registerRouteInstancefunction.Update the
data.registerRouteInstancefunction as follows:data.registerRouteInstance = (vm, val) => { // val could be undefined for unregistration var current = matched.instances[name]; if ((val && current !== vm) || (!val && current === vm)) { matched.instances[name] = val; } };The change here is to check if the
valandmatched.instances[name]are different, or ifvalis falsy andmatched.instances[name]is the same asvm. This ensures that theregisterRouteInstancehook is only called when the instance has actually changed.Save the changes to the
view.jsfile.
Rebuild and Test the Project
In this step, you will rebuild the vue-router-2.5.2 project and test the fixed effect.
- Open the
vue-router-2.5.2directory in the terminal. - 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. - Open the "Web 8080" tab in the VM to see the updated application.
- Click on the "to /", "to /b", and "to /" buttons to verify that the issue has been fixed.
The page should now display the correct content when revisiting the route, as shown in the updated effect:

Congratulations! You have successfully fixed the issue in the vue-router-2.5.2 version of the code.
Summary
Congratulations! You have completed this project. You can practice more labs in LabEx to improve your skills.



