我正在嘗試獲取我的頁面的路徑getServerSideProps,但型別params是物件
我需要做什么才能獲得字串?
export const getServerSideProps: GetServerSideProps = async (context) => {
const { slug } = context.params // Property 'slug' does not exist on type 'ParsedUrlQuery | undefined'.ts(2339)
return {
props: {
},
}
}
uj5u.com熱心網友回復:
如果您正在尋找作為字串的路徑,您可以嘗試context.req.url. (有關屬性的完整串列,請參閱檔案context)。
對于動態引數,這取決于你所指定的頁面,例如,如果你有一個博客文章頁面,用pages/posts/[post].js檔案中,嵌入將在context.params.post而不是context.params.slug。
希望這是有幫助的!
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/338720.html
標籤:javascript 打字稿 下一个.js
