title: Nextjs UseEffect is not rendering on route change
body: <p>I am having problem with a useEffect inside a  component which is in every component. I have made some authentication and redirects in that component but I figured that when I use Nextjs link or the go back button from the browser, the Layout useEffect is not re rendering which means it is not checking if the user is logged in for example.</p>
  <p>here's my layout component</p>
  <pre><code>const Layout = ({ children }) =&gt; {
  
    const router = useRouter()
    const { setAuthenticated, userFromDB, setUserFromDB, setIsVender, isVender } = useContext(AuthContext)
  
    //cuando hacemos un login el token se guarda en el local storage asi que comprobamos que exista
    useEffect(() =&gt; {
      const checkToken = async () =&gt; {
        const token = localStorage.getItem('FBIdToken')
        if (token) {
          const decodedToken = jwtDecode(token);
          //si la fecha de expiracion del token supero a la actual, redirect al login
          if (decodedToken.exp * 1000 &lt; Date.now()) {
            setAuthenticated(false)
            router.replace('/login');
          } else {
            if(!userFromDB){
              const user = await getUser(decodedToken.user_id);
              //si encontro un usuario, lo asignamos al context api
              if(user){
                console.log(user)
                //  obtenemos el objecto con los datos del usuario y seteamos en el context si es vendedor o no
                if(typeof user.isVender !== undefined){
                  user.isVender ? setIsVender(true) : setIsVender(false);
                }
                setUserFromDB(user);
              }
              setAuthenticated(true)
            }
          }
          console.log('ejecutando');
        } else {
          if(router.pathname !== &quot;/&quot; &amp;&amp; 
              router.pathname !== &quot;/download-app&quot; &amp;&amp; 
              router.pathname !== &quot;/register&quot; &amp;&amp; 
              router.pathname !== &quot;/login&quot;
            ) {
            console.log(router.pathname, 'redirigiendo')
            router.replace('/login')
          }
          
        }
      }
      //comprobamos que haya un token y redirigimos al usuario en base a el
      checkToken();
      // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [isVender])
  
  
    return (
      &lt;div&gt;
        {children}
      &lt;/div&gt;
    )
  }
  </code></pre>
  <p>this is how I import it inside the _app.js component</p>
  <pre><code>  return (
      &lt;AuthProvider&gt;
        &lt;Layout&gt;
          &lt;Component {...pageProps} /&gt;
        &lt;/Layout&gt;
      &lt;/AuthProvider&gt;
    )
  }
  
  </code></pre>
  <p>I hope you can help me, thanks in advance!</p>