I am using nextjs/reactjs and need some help on how to redirect to a page
Folder structure
-Pages
-business
-location.js
-selectlocation.js
The URL =http://myhost/business/location?city=Pensacola&state=FL
When the argument is missing, I want to redirect to selectlocation
How do I route to the selectlocation page from the location page when the argument is empty
This is a snippet of my code for location.js
export default class extends Component {
static getInitialProps({ query: { city, state } }) {
return { city: city, state: state };
}
render() {
return (
<div>
<Head>
<title>{title}</title>
<meta name="description" content={description} />
</Head>
<LayoutWithHeader
banner={false}
view="business"
link="location banner"
locationCity={this.props.city}
locationState={this.props.state}>
<Location />
</LayoutWithHeader>
</div>
);
}
}
Code for SelectLocation.JS
export default () => (
<div>
<Head>
<title>Location</title>
</Head>
<LayoutWithHeader banner={true} title="Home / Business / Locations" >
<SelectLocation />
</LayoutWithHeader>
</div>
);