Is my approach the most optimal ?
Unanswered
Red-necked Grebe posted this in #help-forum
Red-necked GrebeOP
So, I have a route called "category" , and a sub-route as a slug called [categoryID] , I want when the user visits /category to be redirected into /category/1 , and my approach to do so was simply creating a page.tsx inside /category, and returning a redirect() function to category/1 , is this the most optiomal approach ? is there a more standard one ?
// /category/page.tsx
import { redirect } from "next/navigation";
type Props = {};
function page({}: Props) {
return redirect("/category/1");
}
export default page;
// /category/page.tsx
import { redirect } from "next/navigation";
type Props = {};
function page({}: Props) {
return redirect("/category/1");
}
export default page;
2 Replies
though there are many different ways to perform redirects in nextjs, they all have tradeoffs so use the one that works for your use case