M
M
MichaelPeterson2019-08-30 03:55:52
JavaScript
MichaelPeterson, 2019-08-30 03:55:52

How to implement a redirect to other domains in the vue.js code?

There is a code with geotargeting. When entering the site, the user sees a pop-up with the question "Your city (for example) Moscow?". Click yes and stay on the site. Presses "no" and a pop-up pops up with a list of the city. How to add this code so that cities are links to regional subdomains?

// Generated by CoffeeScript 2.3.2
$(document).ready(function() {
  var city_address_map;
  city_address_map = {
    'Казань': 'ул. Петербургская 9, ТЦ Республика',
    'Волгоград': 'ул. Землячки 110Б, ТЦ Мармелад',
    'Смоленск': 'ул. 25 Сентября, 35а ТЦ Макси',
    'Ярославль': 'ул. Гоголя, 2 ТЦ Фараон',
    'Благовещенск': 'ул. Тенистая 160 ТЦ Флагман'
  };
  window.vue_header_city_block = new Vue({
    el: '#vue_header_city_block',
    data: function() {
      return {
        geolocation: {},
        geolocation_city: false,
        geolocation_confirmed: '',
        city_address_map: city_address_map
      };
    },
    mounted: function() {
      return this.$nextTick(function() {
        return $('#vue_header_city_block').show();
      });
    },
    methods: {
      confirm_geolocation: function() {
        Cookies.set('voytech_geolocation_confirmed', 'yes', {
          expires: 30,
          path: '/'
        });
        return this.geolocation_confirmed = 'yes';
      },
      dismis_geolocation: function() {
        Cookies.set('voytech_geolocation_confirmed', 'no', {
          expires: 30,
          path: '/'
        });
        return this.geolocation_confirmed = 'no';
      }
    }
  });
  window.vue_header_city_block_mobile = new Vue({
    el: '#vue_header_city_block_mobile',
    data: function() {
      return {
        geolocation: {},
        geolocation_city: false,
        geolocation_confirmed: '',
        city_address_map: city_address_map
      };
    },
    mounted: function() {
      return this.$nextTick(function() {
        return $('#vue_header_city_block_mobile').show();
      });
    },
    watch: {
      geolocation_city: function() {
        var self;
        self = this;
        console.log(self.geolocation_city);
        if (self.geolocation_city && self.city_address_map.hasOwnProperty(self.geolocation_city)) {
          if ($('#mobile_city_address_block').length === 0) {
            return $('[data-id="9ea2ea0"]').after(`<div id='mobile_city_address_block'>Адрес: ${self.city_address_map[self.geolocation_city]}</div>`);
          } else {
            // $('.elementor-element').each (i,c)->

            // 	if $(c).text().indexOf('Заказать звонок') isnt -1

            // 		if $('#mobile_city_address_block').length is 0
            // 			$(c).after "<div id='mobile_city_address_block'>Адрес: #{self.city_address_map[self.geolocation_city]}</div>"
            return $('#mobile_city_address_block').text(`Адрес: ${self.city_address_map[self.geolocation_city]}`);
          }
        } else {
          return $('#mobile_city_address_block').text('');
        }
      }
    },
    methods: {
      confirm_geolocation: function() {
        Cookies.set('voytech_geolocation_confirmed', 'yes', {
          expires: 30,
          path: '/'
        });
        return this.geolocation_confirmed = 'yes';
      },
      dismis_geolocation: function() {
        Cookies.set('voytech_geolocation_confirmed', 'no', {
          expires: 30,
          path: '/'
        });
        return this.geolocation_confirmed = 'no';
      }
    }
  });
  window.vue_city_select_popup = new Vue({
    el: '#vue_city_select_popup',
    data: function() {
      return {
        geolocation: {},
        geolocation_city: false,
        city_search_query: '',
        city_search_results: [],
        popular_cities: ['Казань', 'Ярославль', 'Благовещенск', 'Смоленск', 'Набережные Челны', 'Москва', 'Санкт-Петербург', 'Екатеринбург', 'Новосибирск', 'Пермь', 'Воронеж', 'Челябинск', 'Уфа', 'Владивосток', 'Волгоград', 'Красноярск', 'Нижний Новгород', 'Омск', 'Ростов-на-Дону', 'Самара', 'Саратов', 'Хабаровск']
      };
    },
    methods: {
      select_city: function(city_name, type) {
        console.log('select_city', city_name, type);
        if (type === 'popular') {
          window.vue_header_city_block.geolocation.city = city_name;
          window.vue_header_city_block.geolocation_city = city_name;
          window.vue_header_city_block.confirm_geolocation();
          window.vue_header_city_block_mobile.geolocation.city = city_name;
          window.vue_header_city_block_mobile.geolocation_city = city_name;
          window.vue_header_city_block_mobile.geolocation_city = city_name;
          window.vue_header_city_block_mobile.geolocation_city = city_name;
          window.vue_header_city_block_mobile.geolocation_city = city_name;
          window.vue_header_city_block_mobile.confirm_geolocation();
          Cookies.set('voytech_geolocation', JSON.stringify({
            city: city_name
          }), {
            expires: 30,
            path: '/'
          });
          window.location.hash = 'close';
        }
        if (type === 'search') {
          window.vue_header_city_block.geolocation.city = city_name;
          window.vue_header_city_block.geolocation_city = city_name;
          window.vue_header_city_block.confirm_geolocation();
          window.vue_header_city_block_mobile.geolocation.city = city_name;
          window.vue_header_city_block_mobile.geolocation_city = city_name;
          window.vue_header_city_block_mobile.confirm_geolocation();
          Cookies.set('voytech_geolocation', JSON.stringify({
            city: city_name
          }), {
            expires: 30,
            path: '/'
          });
          return window.location.hash = 'close';
        }
      }
    },
    watch: {
      city_search_query: function() {
        var api_url, payload, self;
        self = this;
        console.log(self.city_search_query);
        if (self.city_search_query !== '') {
          payload = {
            query: self.city_search_query,
            contentType: 'city',
            withParent: 1,
            typeCode: 7,
            limit: 10
          };
          api_url = '/wp-content/themes/oceanwp/voytech_geo.php';
          return $.getJSON(api_url, payload, function(res) {
            var i, item, len, ref, results;
            console.log(res);
            self.city_search_results = res.result;
            self.city_search_results = [];
            ref = res.result;
            results = [];
            for (i = 0, len = ref.length; i < len; i++) {
              item = ref[i];
              if (item.id.toLowerCase() !== 'free') {
                results.push(self.city_search_results.push(item));
              } else {
                results.push(void 0);
              }
            }
            return results;
          });
        } else {
          return self.city_search_results = [];
        }
      }
    }
  });
  if (Cookies.get('voytech_geolocation_confirmed') === 'yes') {
    window.vue_header_city_block.geolocation_confirmed = 'yes';
    window.vue_header_city_block_mobile.geolocation_confirmed = 'yes';
  } else {
    window.vue_header_city_block.geolocation_confirmed = 'no';
    window.vue_header_city_block_mobile.geolocation_confirmed = 'no';
  }
  if (Cookies.get('voytech_geolocation')) {
    window.vue_header_city_block.geolocation = JSON.parse(Cookies.get('voytech_geolocation'));
    window.vue_header_city_block.geolocation_city = JSON.parse(Cookies.get('voytech_geolocation')).city;
    window.vue_header_city_block_mobile.geolocation = JSON.parse(Cookies.get('voytech_geolocation'));
    window.vue_header_city_block_mobile.geolocation_city = JSON.parse(Cookies.get('voytech_geolocation')).city;
    window.vue_city_select_popup.geolocation = JSON.parse(Cookies.get('voytech_geolocation'));
    return window.vue_city_select_popup.geolocation_city = JSON.parse(Cookies.get('voytech_geolocation')).city;
  } else {
    return ymaps.ready(function() {
      window.vue_header_city_block.geolocation = ymaps.geolocation;
      window.vue_header_city_block.geolocation_city = ymaps.geolocation.city;
      window.vue_header_city_block_mobile.geolocation = ymaps.geolocation;
      window.vue_header_city_block_mobile.geolocation_city = ymaps.geolocation.city;
      window.vue_city_select_popup.geolocation = ymaps.geolocation;
      window.vue_city_select_popup.geolocation_city = ymaps.geolocation.city;
      return Cookies.set('voytech_geolocation', JSON.stringify(ymaps.geolocation), {
        expires: 30,
        path: '/'
      });
    });
  }
});

// setInterval(->
// 	console.log $('.prmn-cmngr__confirm .prmn-cmngr__popup .mobile')
// , 500)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Mikhnevich, 2019-08-30
@timartinov

Everything you need is here:
https://router.vuejs.org/en/guide/essentials/redir...

const router = new VueRouter({
  routes: [
    { path: '/a', redirect: to => {
      // в функцию в качестве аргумента передаётся маршрут
      // возвращаемым значением должна быть строка или объект пути
    }}
  ]
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question