Is it possible for server parser to update the url with default query? #507
-
Hi :) const getDefaultArticleType = ({
hasPodcast,
hasVideo,
hasArticle,
}: {
hasPodcast: boolean;
hasVideo: boolean;
hasArticle: boolean;
}) => {
if (hasArticle) return ARTICLE_TYPE.ARTICLE;
if (hasVideo) return ARTICLE_TYPE.VIDEO;
if (hasPodcast) return ARTICLE_TYPE.PODCAST;
return null;
};
const defaultArticleType = getDefaultArticleType({
hasPodcast: !!data?.attributes.audio,
hasVideo: !!data?.attributes.video,
hasArticle: !!data?.attributes.text,
});
if (!defaultArticleType) notFound();
const articleTypeParser = parseAsStringEnum<ARTICLE_TYPE>(
Object.values(ARTICLE_TYPE),
).withDefault(defaultArticleType);
const articleType = articleTypeParser.parseServerSide(
searchParams.type?.toLowerCase(),
); Sometimes example: if user goes to this url: I am using the Thanks :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If you want to update the URL sever-side, this sounds like a job for a middleware.
Indeed. However |
Beta Was this translation helpful? Give feedback.
If you want to update the URL sever-side, this sounds like a job for a middleware.
Indeed. However
nuqs
can help you build that URL, with the serializer helper.