试图熟悉nextJS 13。我遇到的是getServerSideProps函数没有预渲染页面道具。这是我第一次尝试,所以我不知道我是否做错了。
这是编写的代码/app/login/page.js
import Content from "@/components/content";
import LoginForm from "@/components/loginForm";
import Title from "@/components/title";
function Login({ message }) {
return (
<Content>
<div className="ml-2 my-2">
{message || "NextJS is ok."}
<Title text="Login" />
</div>
<LoginForm />
</Content>
);
}
export default Login;
export async function getServerSideProps() {
console.log("running getServerSideProps function..");
return {
props: { message: "NextJS is awesome!" },
};
}
Run Code Online (Sandbox Code Playgroud)
我在这里想要实现的关键是在显示登录页面之前使用 axios 请求检查服务器的会话密钥。如果用户已登录,则应将用户重定向到主页。如果我能够使这个函数工作,这是未来的代码:
export async function getServerSideProps() {
console.log("Im running getServerSideProps funct ");
let isLoggedIn …Run Code Online (Sandbox Code Playgroud)