a = await fetch("https://ega.bet/bets?ajax=&st=0&ut=0&f=", {"credentials":"include","headers":{"accept":"application/json, text/javascript, */*; q=0.01","accept-language":"en-US,en;q=0.9","cache-control":"no-cache","pragma":"no-cache","x-csrf-token":"stgtVCEQDZW6ATbIo2sBBFor6yXyHwEstZsxELKcLhOcWN5jqJgK9xLPKuvc8KzdR5XJT5/ap8RFG25ZPHXkBg==","x-egb-locale":"ru","x-newrelic-id":"VQ4FV19XCRAJUlVVAQAEVw==","x-requested-with":"XMLHttpRequest"},"referrer":"https://ega.bet/","referrerPolicy":"no-referrer-when-downgrade","body":null,"method":"GET","mode":"cors"});
// Response {type: "basic", url: "https://ega.bet/bets?ajax=&st=0&ut=0&f=", redirected: false, status: 200, ok: true, …}
await a.json()
// {user_time: 1564574569, ut: 0, bets: Array(150), nested_bets: Array(723)}
a = await fetch("https://ega.bet/bets?ajax=&st=0&ut=0&f=", {
"headers": {
"accept":"application/json, text/javascript, */*; q=0.01",
"x-requested-with":"XMLHttpRequest"
}
});
await a.json()
Проблема в том что при каждом смене url меню обновляется сменяя активный класс
<main>
<LeftMenu />
<Switch>
<Route path='/dashboards/1' component={Dash1} />
<Route path='/dashboards/2' component={Dash2} />
...
</Switch>
</main>
// App.js
import React from 'react'
import './App.css'
import { BrowserRouter, Link, Switch, Route } from 'react-router-dom'
class Post extends React.Component {
componentDidMount() {
if (this.props.location.pathname === '/post/comments') {
this.scrollToComments()
}
}
componentDidUpdate() {
if (this.props.location.pathname === '/post/comments') {
this.scrollToComments()
}
}
scrollToComments() {
const element = document.querySelector('#comments')
element.scrollIntoView()
}
render() {
return (
<>
<h1>Post</h1>
<div>{new Array(100).fill(<p>long post</p>)}</div>
<h2 id='comments'>Comments</h2>
<div>{new Array(100).fill(<p>comment</p>)}</div>
</>
)
}
}
function App() {
return (
<BrowserRouter>
<div className='App'>
<nav>
<Link to='/post'>go to post</Link>
<Link to='/post/comments'>go to comments</Link>
</nav>
<main>
<Switch>
<Route path='/post' component={Post} />
{/*
other routes
*/}
</Switch>
</main>
</div>
</BrowserRouter>
)
}
export default App