Is it possible to render a new page on same url?
Unanswered
Spectacled bear posted this in #help-forum
Spectacled bearOP
Hi there, I need to show the /restricted page on the dashboard page when the user is not authorized. Is there a way where I can render a different page but the URL stays the same?
For example, show /restricted page but the URL should remain intact i.e
For example, show /restricted page but the URL should remain intact i.e
app.com/dashboard5 Replies
@Spectacled bear Hi there, I need to show the /restricted page on the dashboard page when the user is not authorized. Is there a way where I can render a different page but the URL stays the same?
For example, show /restricted page but the URL should remain intact i.e app.com/dashboard
sounds like you are looking for rewrites ([next.config.js](https://nextjs.org/docs/app/api-reference/next-config-js/rewrites), [middleware](https://nextjs.org/docs/app/api-reference/functions/next-response#rewrite))
@joulev sounds like you are looking for rewrites ([next.config.js](<https://nextjs.org/docs/app/api-reference/next-config-js/rewrites>), [middleware](<https://nextjs.org/docs/app/api-reference/functions/next-response#rewrite>))
Spectacled bearOP
I don't think that matches the requirement. I want to handle this config inside the page itself since it is a conditional thing.
then i doubt it is possible, no.
unless you do like
but then if you do this it's better to make the
unless you do like
import RestrictedPage from "~/app/restricted/page";
if (restricted) return <RestrictedPage />but then if you do this it's better to make the
RestrictedPage an ordinary component rather than a page (and get rid of /restricted altogether)@joulev then i doubt it is possible, no.
unless you do like
tsx
import RestrictedPage from "~/app/restricted/page";
if (restricted) return <RestrictedPage />
but then if you do this it's better to make the `RestrictedPage` an ordinary component rather than a page (and get rid of `/restricted` altogether)
Spectacled bearOP
yeah i get it, but was it possible earlier in next js?