import logo from './logo.svg';
import './App.css';
import $ from 'jquery';
import { BrowserRouter as Router,Route,Switch,Redirect } from "react-router-dom";
import Home from './Home';
import Login from './Login';
// Getting the country code from the user's IP
// List of countries we want to block
// To see this in action add your country code to the array
var blacklist = ['US', 'CA', 'UK','IN']
// Getting the country code from the user's IP
$.get("https://api.ipdata.co?api-key=97173fac13f575130327fc00f93b12fe62ea33afb45930438111a4ea", function (response) {
// Checking if the user's country code is in the blacklist
// You could inverse the logic here to use a whitelist instead
if (blacklist.includes(response.country_code)) {
<Redirect push to="/home" />
alert('This content is not available at your location.');
} else {
alert("You're allowed to see this!")
}
}, "jsonp");
function App() {
return (
<>
<Router>
<Switch>
<Route exact path="/" component={Login}/>
<Route exact path="/home" component={Home}/>
<Redirect to="/"/>
</Switch>
</Router>
</>
);
}
export default App;
I am blocking the users from specific country using api of ipdata,I want that it should redirect me after showing the alert that this content is not avalible, but I am not getting redirected after I see the alert.When I use windows.location command that its redirecting me again and again very quickly.