import { redirect } from 'next/navigation'可以在SSR中解决此问题 假设你有一个用于创建新博客文章的url/route,名为/new-post,你想为一个非授权用户保护这个url,并将他们重定向到其他页面。 这就是你在那种情况下要做的
const newPost = async () => {
const loginStatus = await getLoginStatus() // get the login status
if (!loginStatus.isLoggedIn) {
redirect('/') // Redirect them to other pages that can access by any non-auth user
}
return (
<div>
/* Create new post page content here */
</div>
)
}
export default newPost
由于所有组件都是在服务器上运行的,所以在nextjs 13中,这将在服务器上准备就绪。 Refer to docs
1条答案
按热度按时间siotufzp1#
import { redirect } from 'next/navigation'
可以在SSR中解决此问题假设你有一个用于创建新博客文章的url/route,名为
/new-post
,你想为一个非授权用户保护这个url,并将他们重定向到其他页面。这就是你在那种情况下要做的
由于所有组件都是在服务器上运行的,所以在nextjs 13中,这将在服务器上准备就绪。
Refer to docs