#How to replicate 404 page behavior

2 messages · Page 1 of 1 (latest)

burnt leaf
#

(talking about /pages) The 404.tsx file behaves differently than most pages in the file router, in that it renders the 404 page, but does not change the URL.

I am trying to implement similar behavior, for RBAC related purposes. E.g. the user receives a generic "you cannot access this page" but the URL stays the same.

I tried actually using the 404 page for this purpose, where (in getServerSideProps) I {notFound:true} the request if it's truly not found OR they don't have access. And then on the client, I determine whether to show a true 404 or a "no access page".

This was working until removal of getInitialProps in _app caused the 404 page to be statically generated, and now useRouter yields an empty query object, which I was previously using to determine whether to show a 404 or no access page.

SO, Is there a way for me to send users to a "no access page", but preserve the URL that they originally accessed? I.e. I don't want to redirect them to /no-access, I want them to stay on /:teamId/admin but be shown a no-access page.

dull laurelBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

      🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in <id:customize>

      ✅ You can mark a message as the answer for your post with `Right click -> Apps -> Mark Solution`
      (if you don't see the option, try refreshing Discord with Ctrl + R)