-
Notifications
You must be signed in to change notification settings - Fork 3
/
client2.js
30 lines (29 loc) · 999 Bytes
/
client2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import React, { useEffect,useState } from "react";
import Router from 'next/router'
const enviroment = process.browser ? "client side" : "server side"
const ClientSide2 = ()=>{
const [loaded,setLoaded] = useState(false)
useEffect(() => {
console.log(enviroment)
const {pathname} = Router
// conditional redirect
if(pathname == '/client2' ){
// with router.push the page may be added to history
// the browser on history back will go back to this page and then forward again to the redirected page
// you can prevent this behaviour using location.replace
Router.push('/target')
//location.replace("/target")
}else{
setLoaded(true)
}
},[]);
if(!loaded){
return <div></div> //show nothing or a loader
}
return (
<p>
You will see this page only if pathname !== "client2" , <br/>
</p>
)
}
export default ClientSide2