简体   繁体   English

如何禁用地理定位?

[英]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我正在使用 react.js 和模块 useposition 但我想知道如果我将 go 直接指向此路径,我该如何禁用地理定位弹出窗口: 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我的意思是如果我 go 到这条路线: http://localhost:3000/activation => 我没有地理定位的弹出窗口

if I go to this route: http://localhost:3000 => I have the popup of gelolocalization如果我 go 到这条路线: http://localhost:3000 => 我有 geolocalization 的弹出窗口

Could you help me please?请问你能帮帮我吗?

Thank you very much !非常感谢 !

Use the usePosition only if not in the specified path and use <Switch> to only use one of the declared routes:仅当不在指定路径中时才使用usePosition并使用<Switch>仅使用声明的路由之一:

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM