Next.js Discord

Discord Forum

NextRouter was not mounted

Answered
Flemish Giant posted this in #help-forum
Open in Discord
Flemish GiantOP
Trying to check if a user is AlphaUser or not. Back-end dev is still implementing this so currently just using static variable (bare with me)

"use client";

import { useEffect } from 'react';
import { useRouter } from 'next/router';

const Home = () => {
  const isAlphaUser = true; // Replace this with the actual check once the API is ready
  const router = useRouter();

  useEffect(() => {
    // Check if the user is not an alpha user
    if (!isAlphaUser) {
      // Redirect to the /alpha route
      router.push('/alpha');
    }
  }, [isAlphaUser, router]);

  return (
    <main>
      {/* Your main content goes here */}
    </main>
  );
};

export default Home;


I get this error though:
Answered by riský
app dir has useRouter from next/navigation
View full answer

14 Replies

Answer
Flemish GiantOP
ah
thank you 🙏 @riský
beside this, this a good enough check?
tbh its a common issue that people have
@riský tbh its a common issue that people have
Flemish GiantOP
the error message should include that fix tbh
@Flemish Giant beside this, this a good enough check?
i mean, if server component, you can bypass client and just use redirect from next/navigation
Flemish GiantOP
even though it links to the docs which say it i'm just dumb 😭
client component
its the user dashboard
yeah thats fine
Flemish GiantOP
great, thank you so much
have a nice day
you tooo :)))