<commit_before>import React from 'react';
import {Application} from '../components';
import {Logout, Login, Home, NotFound, Products} from '../pages';
import {Router, Route, IndexRoute, browserHistory} from 'react-router';
import store from '../store';

const requireAuth = (nextState, replace) => {
  const {isAuth, isLoading} = store.getState().session;
  if (!isAuth && !isLoading) {
    replace({
      pathname: '/login',
      state: {
        nextPathname: nextState.location.pathname
      }
    });
  }
};

function MustNotBeLogged(nextState, replace) {
  const {isAuth, isLoading} = store.getState().session;
  if (isAuth && !isLoading) {
    replace({
      pathname: '/',
      state: {
        nextPathname: nextState.location.pathname
      }
    });
  }
}

const Routes = props => {
  return (
    <Router history={browserHistory}>
      <Route path="/" component={Application}>
        <IndexRoute component={Home} onEnter={requireAuth}/>
        <Route path="search/:search" component={Products} onEnter={requireAuth}/>
        <Route path="category/:category" component={Products} onEnter={requireAuth}/>
        <Route path="login" component={Login} onEnter={MustNotBeLogged}/>
        <Route path="logout" component={Logout}/>
        <Route path="*" component={NotFound} onEnter={requireAuth}/>
      </Route>
    </Router>
  );
};

export {Routes};
export default Routes;
<commit_msg>go back to top on route change<commit_after>import React from 'react';
import {Application} from '../components';
import {Logout, Login, Home, NotFound, Products} from '../pages';
import {Router, Route, IndexRoute, browserHistory} from 'react-router';
import store from '../store';

browserHistory.listen(location => {
  window.scrollTo(0, 0);
});

const requireAuth = (nextState, replace) => {
  const {isAuth, isLoading} = store.getState().session;
  if (!isAuth && !isLoading) {
    replace({
      pathname: '/login',
      state: {
        nextPathname: nextState.location.pathname
      }
    });
  }
};

function MustNotBeLogged(nextState, replace) {
  const {isAuth, isLoading} = store.getState().session;
  if (isAuth && !isLoading) {
    replace({
      pathname: '/',
      state: {
        nextPathname: nextState.location.pathname
      }
    });
  }
}

const Routes = props => {
  return (
    <Router history={browserHistory}>
      <Route path="/" component={Application}>
        <IndexRoute component={Home} onEnter={requireAuth}/>
        <Route path="search/:search" component={Products} onEnter={requireAuth}/>
        <Route path="category/:category" component={Products} onEnter={requireAuth}/>
        <Route path="login" component={Login} onEnter={MustNotBeLogged}/>
        <Route path="logout" component={Logout}/>
        <Route path="*" component={NotFound} onEnter={requireAuth}/>
      </Route>
    </Router>
  );
};

export {Routes};
export default Routes;

{'fraction_non_alphanumeric': 0.15924006908462868, 'fraction_numerical': 0.000690846286701209, 'mean_word_length': 3.525, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3348961', 'n_tokens_mistral': 861, 'n_tokens_neox': 859, 'n_words': 203}