type Properties = {
params: Promise<{ slug: string }>
}
export default async function HousingDetailPage({ params }: Properties) {
const { slug } = await params
const housing = await getHousingById(slug)
...
export async function getHousingById(id: string): Promise<HousingUnit | null> {
console.log('getHousingById', `${API_PATH}/db-apartments/${id}`);
try {
// Use the rewrite rule to get data
const response = await fetch(`${API_PATH}/db-apartments/${id}`, {
headers: {
'Accept': 'application/json',
}
});
// If the response is not OK, it means the housing unit wasn't found
if (!response.ok) {
console.error(`Housing unit with ID ${id} not found`);
return null;
}
const data = await response.json();
return data;
} catch (error) {
console.error(`Error fetching housing unit with ID ${id}:`, error);
return null;
}
}
type Properties = {
params: Promise<{ slug: string }>
}
export default async function HousingDetailPage({ params }: Properties) {
const { slug } = await params
const housing = await getHousingById(slug)
...
export async function getHousingById(id: string): Promise<HousingUnit | null> {
console.log('getHousingById', `${API_PATH}/db-apartments/${id}`);
try {
// Use the rewrite rule to get data
const response = await fetch(`${API_PATH}/db-apartments/${id}`, {
headers: {
'Accept': 'application/json',
}
});
// If the response is not OK, it means the housing unit wasn't found
if (!response.ok) {
console.error(`Housing unit with ID ${id} not found`);
return null;
}
const data = await response.json();
return data;
} catch (error) {
console.error(`Error fetching housing unit with ID ${id}:`, error);
return null;
}
}