article-slug滚动至顶

This commit is contained in:
tangly1024
2022-09-22 21:57:25 +08:00
parent 744b314105
commit 43fa245572

View File

@@ -5,7 +5,7 @@ import { useGlobal } from '@/lib/global'
import * as ThemeMap from '@/themes'
import React from 'react'
import { idToUuid } from 'notion-utils'
import { useRouter } from 'next/router'
import Router from 'next/router'
import { isBrowser } from '@/lib/utils'
/**
@@ -17,10 +17,10 @@ const Slug = props => {
const { theme, changeLoadingState } = useGlobal()
const ThemeComponents = ThemeMap[theme]
const { post, siteInfo } = props
const router = Router.useRouter()
if (!post) {
changeLoadingState(true)
const router = useRouter()
setTimeout(() => {
if (isBrowser()) {
const article = document.getElementById('container')
@@ -48,9 +48,9 @@ const Slug = props => {
}, [post])
/**
* 验证文章密码
* @param {*} result
*/
* 验证文章密码
* @param {*} result
*/
const validPassword = result => {
if (result) {
setLock(false)
@@ -69,6 +69,10 @@ const Slug = props => {
tags: post?.tags
}
Router.events.on('routeChangeComplete', () => {
window.scrollTo({ top: 0, behavior: 'smooth' })
})
return (
<ThemeComponents.LayoutSlug {...props} showArticleInfo={true} meta={meta} />
)