Skip to content
Advertisement

How can I do to disable geolocalization?

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

import {usePosition} from "use-position";
import { BrowserRouter as Router, Route } from "react-router-dom";
import Activation from "./components/activation/activation";
import {Popup} from "react-leaflet";

const App = () => {
    const { latitude, longitude, timestamp, accuracy, error } = usePosition();

    return (
            <>
                <p>We are there</p>                   
                <Router>
                <Route path="/activate/:token" component={Activation} />
                </Router>
            </>
        );
};

export default App;

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:

import {usePosition} from "use-position";
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
import Activation from "./components/activation/activation";
import {Popup} from "react-leaflet";

const WithPosition () => {
    const { latitude, longitude, timestamp, accuracy, error } = usePosition();
    return (
      <div>Whatever rest of contents</div>
    )
}

const App = () => {
    return (
        <>
            <p>We are there</p>                
            <Router>
                <Switch>
                    <Route path="/activate/:token" component={Activation} />
                    <Route component={WithPosition} />
                </Switch>
            </Router>
        </>
    );
};

export default App;
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement