📝 [doc] Reset scrollBar after switching page route#72
Merged
higuaifan merged 1 commit intoshuimo-design:mainfrom Feb 23, 2024
Merged
📝 [doc] Reset scrollBar after switching page route#72higuaifan merged 1 commit intoshuimo-design:mainfrom
higuaifan merged 1 commit intoshuimo-design:mainfrom
Conversation
higuaifan
reviewed
Feb 23, 2024
Member
There was a problem hiding this comment.
🤔How about use router guards?(just discussing)
It is better to add comments to new files.
Contributor
Author
There was a problem hiding this comment.
If use router guards like below, it works fine now, but may cause some hidden bugs in the future. Because if adding anchors in the future, the url will look like http://xxxx.xxx/#any-anchor. When switching anchor rather than page route, the below code will be triggered too. It's not correct. 😕
const router = useRouter();
router.beforeEach(async (to,from,next) => {
await nextTick();
domRef.value?.scroll(0, 0);
next();
})So the safe code should be like below.
const router = useRouter();
router.beforeEach(async (to,from,next) => {
if(to.path !== from.path) {
await nextTick();
domRef.value?.scroll(0, 0);
}
next();
})I think it's less succinct than
const route = useRoute();
watch(() => route.path, async () => {
await nextTick();
domRef.value?.scroll(0, 0);
});Ok, I will add comments. 👨🎓
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤔 Nature of this PR
🔗 Related Issue
#71
💡 Background and Solution
Reset the scrollBar of the root dom in
doc.vueandmain.vueto position (0, 0).✅ Pre-merge Checklist
❗️Please self-check and check all options.❗️