Skip to content

how to know if the app is on the not found page in nextjs 14 app router #61823

Discussion options

You must be logged in to vote

My workaround for the issue:

  1. Add app global state/context, i.e. AppContext.js
const [is404, setIs404] = useState(false);
  1. Toggle is404 state inside not-found.tsx
    useEffect(() => {
       setIs404(true);
       return () => setIs404(false);
    }, []);
  1. Get is404 from app global state/context wherever you need it.

Replies: 13 comments 21 replies

Comment options

You must be logged in to vote
3 replies
@abdulvahidkp
Comment options

@mrjackyliang
Comment options

@fiizzy
Comment options

Comment options

You must be logged in to vote
2 replies
@abdulvahidkp
Comment options

@icyJoseph
Comment options

Comment options

You must be logged in to vote
2 replies
@shriekdj
Comment options

@Shreykr
Comment options

Comment options

You must be logged in to vote
2 replies
@shriekdj
Comment options

@rimoslav
Comment options

Comment options

You must be logged in to vote
4 replies
@NiicooR
Comment options

@nikhil-unilode
Comment options

@NiicooR
Comment options

@nikhil-unilode
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@Shreykr
Comment options

@nikhil-unilode
Comment options

@Shreykr
Comment options

@nikhil-unilode
Comment options

@Shreykr
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@abdulvahidkp
Comment options

@just2102
Comment options

@just2102
Comment options

Answer selected by abdulvahidkp
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet