Skip to content

with-apollo-auth: getDataFromTree returns an error during SSR with useRouter hook #7731

@nikitowsky

Description

@nikitowsky

Error while running getDataFromTree TypeError: Cannot read property 'query' of null

Describe the bug

I tried to use latest dynamic router functionality next to apollo client (just updated next version in with-apollo-auth example). When I use useRouter hook and trying to load page via visiting dynamic page directly from browser (not via client routing) I get an error Error while running getDataFromTree TypeError: Cannot read property 'query' of null. If I use withRouter hoc - everything is ok!

To Reproduce

// Route like: /users/[user].tsx
import React from 'react';
import { useRouter } from 'next/router';

const UserInfo = (props) => {
  const router = useRouter();

  return <div>Hello {router.query.user}!</div>;
};

export default UserInfo;

Screenshots

image

System information

  • OS: macOS
  • Browser: Chrome
  • Version of Next.js: [e.g. 8.1.1-canary.64]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions