Next.js: Router.beforePopState is not a function

Created on 11 Aug 2019  路  2Comments  路  Source: vercel/next.js

Bug report

Describe the bug

Router.beforePopState is not a function.

To Reproduce

Add a pages/_app.js like this:

import React from "react";
import App, { Container } from "next/app";
import { Router } from "next/router";

class MyApp extends App {
  componentDidMount() {
    Router.beforePopState(({ url, as, options }) => {
      console.log("beforePopState", url, as, options);
      return true;
    });
  }

  render() {
    const { Component, pageProps } = this.props;

    return (
      <Container>
        <Component {...pageProps} />
      </Container>
    );
  }
}

export default MyApp;

Expected behavior

Router.beforePopState should be a function.

Screenshots

Screen Shot 2019-08-11 at 13 55 47

System information

  • OS: macOS 10.14.6
  • Browser: Google Chrome 76.0.3809.100 (Official Build) (64-bit)
  • Version of Next.js: 9.0.3

Additional context

I have tried it with React 16.8.6 and 16.9.0 and it happens with both.

Most helpful comment

Your import is wrong

import { Router } from "next/router";

Should be

import Router from "next/router";

All 2 comments

Your import is wrong

import { Router } from "next/router";

Should be

import Router from "next/router";

Ups. Thanks! 馃槄

Was this page helpful?
0 / 5 - 0 ratings

Related issues

knipferrc picture knipferrc  路  3Comments

pie6k picture pie6k  路  3Comments

ghost picture ghost  路  3Comments

flybayer picture flybayer  路  3Comments

timneutkens picture timneutkens  路  3Comments