【发布时间】:2020-10-14 03:43:01
【问题描述】:
如果不满足特定条件,我是新来的反应并尝试将用户路由到新页面(内部和外部)。我下面的 sn-p 有效,但我不确定这是正确的方法。
请您看一下,如果有更有效的方法可以告诉我。我想在 URL 没有参数或参数无效时自动重定向用户。
谢谢
export default class extends Component {
static getInitialProps({ query: { city, state } }) {
return { city: city, state: state };
}
componentDidMount() {
if (!this.props.city) {
Router.push('INTERNAL URL')
} else {
if (this.props.city === "augusta") {
window.location = 'https://www.google.com'
}
}
}
render() {
if (!this.props.city ||this.props.city === "augusta"){
return null
}else{
return(
<div>...</div>
)
}
}
}
【问题讨论】:
-
你使用的nextjs是什么版本的?