mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 11:06:23 +00:00
✨ feat: 重构评论功能,支持删除和点赞,更新国际化文本,优化组件结构
This commit is contained in:
27
web/src/hooks/use-route.ts
Normal file
27
web/src/hooks/use-route.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { useRouter, usePathname } from "next/navigation"
|
||||
|
||||
/**
|
||||
* 用于跳转到登录页并自动带上 redirect_back 参数
|
||||
* 用法:const toLogin = useToLogin(); <Button onClick={toLogin}>去登录</Button>
|
||||
*/
|
||||
export function useToLogin() {
|
||||
const router = useRouter()
|
||||
const pathname = usePathname()
|
||||
return () => {
|
||||
router.push(`/login?redirect_back=${encodeURIComponent(pathname)}`)
|
||||
}
|
||||
}
|
||||
|
||||
export function clickToUserprofile(username: string) {
|
||||
const router = useRouter()
|
||||
return () => {
|
||||
router.push(`/user/${username}`)
|
||||
}
|
||||
}
|
||||
|
||||
export function clickToPost(postId: number) {
|
||||
const router = useRouter()
|
||||
return () => {
|
||||
router.push(`/p/${postId}`)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user