在nextjs中获取URL路径名

我有一个登录页面和布局组件。布局组件有标题。我不想在登录中显示标题。为此,我想获取url路径名。基于路径名显示标题。

import * as constlocalStorage from '../helpers/localstorage';
import Router from 'next/router';

export default class MyApp extends App {
    componentDidMount(){
        if(constlocalStorage.getLocalStorage()){
            Router.push({pathname:'/app'});
        } else{
            Router.push({pathname:'/signin'});
        }

    }

    render() {
        const { Component, pageProps } = this.props
        return (
//I want here pathname for checking weather to show header or not
                <Layout>
                    <Component {...pageProps} />
                </Layout>
        )
    }
}

请帮忙

2020/03/23 11:56:54

您可以使用window.locationcomponentDidMount()或者componentDidUpdate()是这样的:

componentDidMount() {
  this.currentUrl = window.location;
}