我有一个登录页面和布局组件。布局组件有标题。我不想在登录中显示标题。为此,我想获取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>
)
}
}
请帮忙
您可以使用
window.location
的componentDidMount()
或者componentDidUpdate()
是这样的: