1.发请求-动态meta标签(可开放图谱协议)
src/app/share/page.tsx
params
import axios from 'axios';
type Props = {
params: {
id: string
}
}
export async function generateMetadata( { params }: Props ){
//123
console.log('id',params.id);
const response = await axios.post('https://xxx.com/bot/get.do', `id=${params.id}`)
return {
title: response.data.name,
twitter: {
title: 'test-title',
description: 'test-desc',
},
}
}
export default function Bot() {
return (
<>
<h1></h1>
</>
);
}
src/app/[id]/page.tsx
searchParams
import axios from 'axios';
type Props = {
searchParams: {
[key: string]: string
}
}
export async function generateMetadata( { searchParams }: Props ){
//share?id=123
console.log('search',searchParams);
const response = await axios.post('https://xxx.com/bot/get.do', `id=${searchParams.id}`)
return {
title: response.data.name,
}
}
export default function Bot() {
return (
<>
<h1></h1>
</>
);
}