Skip to content

📝 [doc] Reset scrollBar after switching page route#72

Merged
higuaifan merged 1 commit intoshuimo-design:mainfrom
QJvic:main
Feb 23, 2024
Merged

📝 [doc] Reset scrollBar after switching page route#72
higuaifan merged 1 commit intoshuimo-design:mainfrom
QJvic:main

Conversation

@QJvic
Copy link
Copy Markdown
Contributor

@QJvic QJvic commented Feb 23, 2024

🤔 Nature of this PR

  • 🐛 bug fix
  • ✨ new feature
  • 📝 documentation improvement
  • 🛝 demo code improvement
  • 🚀 component style/interaction improvement
  • 🏗️ ci/cd improvement
  • ♻️ refactoring
  • 🎨 code style optimization
  • ✅ test cases
  • 🔀 branch merging
  • 💡 other

🔗 Related Issue

#71

💡 Background and Solution

Reset the scrollBar of the root dom in doc.vue and main.vue to position (0, 0).

✅ Pre-merge Checklist

❗️Please self-check and check all options.❗️

  • Documentation is supplemented or not needed
  • Code demonstration is provided or not needed
  • TypeScript definitions are supplemented or not needed
  • Changelog is provided or not needed

Copy link
Copy Markdown
Member

@higuaifan higuaifan Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔How about use router guards?(just discussing)

It is better to add comments to new files.

Copy link
Copy Markdown
Contributor Author

@QJvic QJvic Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. 👨‍🎓

@higuaifan higuaifan merged commit 0ee1227 into shuimo-design:main Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants