You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

69 rivejä
1.5 KiB

  1. import Vue from 'vue'
  2. import Router from 'vue-router';
  3. import Resource from 'vue-resource';
  4. import i18n from 'vue-i18n';
  5. import locales from './locales/locales';
  6. import App from './app.vue';
  7. import IndexView from './components/index.vue';
  8. import AuthView from './components/auth/auth.vue';
  9. import LoginView from './components/auth/login.vue';
  10. import RegisterView from './components/auth/register.vue';
  11. import EntriesView from './components/entries.vue';
  12. import auth from './services/auth';
  13. Vue.use(Resource);
  14. Vue.use(Router);
  15. var browserLanguage = (navigator.language || navigator.browserLanguage).split('-')[0];
  16. var lang = browserLanguage in locales ? browserLanguage : 'en';
  17. Vue.use(i18n, {
  18. lang: lang,
  19. locales: locales
  20. });
  21. Vue.http.headers.common['Authorization'] = 'Bearer ' + localStorage.getItem('token');
  22. auth.checkAuth();
  23. export var router = new Router();
  24. router.map({
  25. '/': {
  26. component: IndexView
  27. },
  28. '/entries': {
  29. auth: true,
  30. component: EntriesView
  31. },
  32. '/auth': {
  33. component: AuthView,
  34. subRoutes: {
  35. '/login': {
  36. component: LoginView
  37. },
  38. '/register': {
  39. component: RegisterView
  40. }
  41. }
  42. }
  43. });
  44. router.beforeEach(function () {
  45. window.scrollTo(0, 0)
  46. });
  47. router.redirect({
  48. '*': '/'
  49. });
  50. router.start(App, '#app');
  51. router.beforeEach(function (transition) {
  52. if (transition.to.auth && !auth.user.authenticated) {
  53. transition.redirect('/auth/login')
  54. } else {
  55. transition.next()
  56. }
  57. });