1

When I try to replace using Router.replace() I get the following error:

TypeError: next_router__WEBPACK_IMPORTED_MODULE_6__.Router.replace is not a function

enter image description here

I have tried like this:

import { Router } from "next/router";

  {isAuth() && (
              <NavItem>
                <Link href="/signup">
                  <NavLink
                    style={{ cursor: "pointer" }}
                    onClick={() => signout(() => Router.replace(`/signin`))}
                  >
                    SignOut
                  </NavLink>
                </Link>
              </NavItem>
            )}

Any Suggestion please.

2 Answers 2

2

The docs recommend using it as Hook:

import { useRouter } from 'next/router'

export default function YourComponent(props) {
  const router = useRouter()

  // *** //

 {isAuth() && (
          <NavItem>
            <Link href="/signup">
              <NavLink
                style={{ cursor: "pointer" }}
                onClick={() => signout(() => router.replace(`/signin`))}
              >
                SignOut
              </NavLink>
            </Link>
          </NavItem>
        )}
Sign up to request clarification or add additional context in comments.

Comments

1

Nextjs recommend using useRouter. You can access router object through this hook like this.

import { useRouter } from 'next/router'

export default function Page() {
  const router = useRouter()

  return (
    <NavLink onClick={() => signOut(() => router.replace('/signin'))}>Signout</NavLink>
  )
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.