I am working using react.js and the module useposition but I would like to know how can I do to disable the popup of geolocalization if I go directlry to this path : http://localhost:3000/activation
JavaScript
x
20
20
1
import {usePosition} from "use-position";
2
import { BrowserRouter as Router, Route } from "react-router-dom";
3
import Activation from "./components/activation/activation";
4
import {Popup} from "react-leaflet";
5
6
const App = () => {
7
const { latitude, longitude, timestamp, accuracy, error } = usePosition();
8
9
return (
10
<>
11
<p>We are there</p>
12
<Router>
13
<Route path="/activate/:token" component={Activation} />
14
</Router>
15
</>
16
);
17
};
18
19
export default App;
20
I mean if I go to this route : http://localhost:3000/activation
=> I don’t have the popup of geolocalization
if I go to this route : http://localhost:3000
=> I have the popup of gelolocalization
Could you help me please ?
Thank you very much !
Advertisement
Answer
Use the usePosition
only if not in the specified path and use <Switch>
to only use one of the declared routes:
JavaScript
1
28
28
1
import {usePosition} from "use-position";
2
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
3
import Activation from "./components/activation/activation";
4
import {Popup} from "react-leaflet";
5
6
const WithPosition () => {
7
const { latitude, longitude, timestamp, accuracy, error } = usePosition();
8
return (
9
<div>Whatever rest of contents</div>
10
)
11
}
12
13
const App = () => {
14
return (
15
<>
16
<p>We are there</p>
17
<Router>
18
<Switch>
19
<Route path="/activate/:token" component={Activation} />
20
<Route component={WithPosition} />
21
</Switch>
22
</Router>
23
</>
24
);
25
};
26
27
export default App;
28