title: Next.js server side routing
body: <p>I have this code to check if the user is authenticated</p>
  
  <pre><code>const withAuth = AuthComponent =&gt; {
    class Authenticated extends Component {
      static async getInitialProps (ctx) {
        let componentProps
        if (AuthComponent.getInitialProps) {
          componentProps = await AuthComponent.getInitialProps(ctx)
        }
        return {
          ...componentProps
        }
      }
      componentDidMount () {
        this.props.dispatch(loggedIn())
      }
      renderProtectedPages (componentProps) {
        const { pathname } = this.props.url
        if (!this.props.isAuthenticated) {
          if (PROTECTED_URLS.indexOf(pathname) !== -1) {
            // this.props.url.replaceTo('/login')
            Router.replace('/login')                   // error
          }
        }
        return &lt;AuthComponent {...componentProps} /&gt;
      }
      render () {
        const { checkingAuthState, ...componentProps } = this.props
        return (
          &lt;div&gt;
            {checkingAuthState ? (
              &lt;div&gt;
                &lt;h2&gt;Loading...&lt;/h2&gt;
              &lt;/div&gt;
            ) : (
              this.renderProtectedPages(componentProps)
            )}
          &lt;/div&gt;
        )
      }
    }
    return connect(state =&gt; {
      const { checkingAuthState, isAuthenticated } = state.data.auth
      return {
        checkingAuthState,
        isAuthenticated
      }
    })(Authenticated)
  }
  </code></pre>
  
  <p>It works great but I'm getting this error when I try to redirect the user:</p>
  
  <blockquote>
    <p>No router instance found. You should only use "next/router" inside the client side of your app.</p>
  </blockquote>
  
  <p>if I try to use <code>this.props.url.replaceTo('/login')</code> I get this warning</p>
  
  <blockquote>
    <p>Warning: 'url.replaceTo()' is deprecated. Use "next/router" APIs.</p>
  </blockquote>
  
  <p>so this is making me crazy, I was wondering if there is a way to achieve this redirection or maybe another way to control the authentication in this case just a clue will be great.</p>