1

For me the next.js tutorial https://github.com/zeit/next-learn-demo.git has a problem at all stages past stage 2 "dynamic routing". Even though in the stages afterwards on stages 3 to 8 the dynamic routing should already be working.

What i assumed was the problems is that the file .next/routing appeared to be missing.

As such the tutorial asked implementation of code:

import { useRouter } from 'next/router';

and

const router = useRouter();

does not do anything.

leading to the error on clicking the link:

screenshot of next.js browser syntax error inspection

Why is the routing file not in the .next folder?

the react version is 16.10.2 (installed today through tutorial instructions) the format of code is what is in the tutorial copy pasted. (no hook rule breaking) there are no react duplicates.

5
  • console.log(router) see what that brings up Commented Oct 11, 2019 at 12:43
  • console.log(router) VM38:1 Uncaught ReferenceError: router is not defined at <anonymous>:1:13 does not seem to be available Commented Oct 11, 2019 at 16:48
  • instead of writing it console could you write this console line in your code, i.e. right after const router = useRouter(); Commented Oct 11, 2019 at 18:51
  • THe console doesnt vie anything when i do this. Further there is this in the console: index.js:1 Fetch API cannot load file:///C:/WINDOWS/system32/next-learn-demo/8-deploying/node_modules/next/dist/client/router.js. URL scheme must be "http" or "https" for CORS request. Suggesting that it is not loading for that reason, along with 5 other api fetch requests Commented Oct 15, 2019 at 13:04
  • stackoverflow.com/questions/50445639/… Commented Nov 2, 2019 at 4:30

1 Answer 1

1

I think you are using useRouter() in class component. useRouter is a hook and used only in functional components.

in class components we use withRouter HOC. "router" object is accessible as

this.props.router
Sign up to request clarification or add additional context in comments.

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.