export const routes = [
// menu navigation
{ path: '/', redirect: '/menu' },
{ path: '/menu', component: MenuPage, children: [
{ path: '', component: CategoriesPage, meta: { location: 'Меню' }},
{ path: 'search', component: SearchProductPage, meta: { location: 'Поиск' } },
{ path: ':categoryId', component: CategoryPage, children: [
{ path: '', component: ProductsPage, meta: {bcDynamic: true, bcGetter: 'activeCategory', bcText: category => category.title,} },
{ path: ':productId', component: ProductPage, meta: { bcDynamic: true, bcGetter: 'activeProduct', bcText: product => product.title} }
] }
] },
// profile navigation
{ path: '/profile', component: ProfileViewPage, children: [
{ path: '', component: ProfilePage, meta: { location: 'Профиль' }},
{ path: 'my-data', component: UserDataPage, meta: { location: 'Личные данные' }},
{ path: 'my-orders', component: UserOrdersPage, meta: { location: 'Мои заказы' }},
{ path: 'my-notice', component: UserNoticePage, meta: { location: 'Уведомления' } },
{ path: 'my-promo', component: UserPromoPage, meta: { location: 'Промокод' } },
{ path: 'my-feedback', component: UserFeedbackPage, meta: { location: 'Контакты' } },
]},
{ path: '/login', component: LoginPage, meta: { location: 'Авторизация' } },
{ path: '/registry', component: RegistryPage, meta: { location: 'Регистрация' } },
// ordering navigation
{ path: '/ordering', component: CartViewPage, children: [
{ path: '', component: CartPage, meta: { location: 'Корзина' }},
{ path: 'order', component: OrderPage, meta: { location: 'Заказ' }},
{ path: 'addresses', component: AddressesPage, meta: { location: 'Адрес' }},
{ path: 'address', component: AddressPage, meta: { location: 'Адрес' }},
{ path: 'restaurants', component: ChooseRestaurantPage, meta: { location: 'Выбирете ресторан' }},
{ path: 'summary', component: SummaryOrderPage, meta: { location: 'Оформление' }},
{ path: 'status', component: StatusOrderPage, meta: { location: 'Заказ' }},
] },
// discounts navigation
{ path: '/promo', component: DiscountsPage, children: [
{ path: '', component: DiscountsListPage, meta: { location: 'Акции' } },
{ path: ':promoId', component: PromoDetailPage, meta: { bcDynamic: true, bcGetter: 'activeDiscount', bcText: discount => discount.title} }
] },
// restaurants navigation
{ path: '/restaurants', component: RestaurantsViewPage, children: [
{ path: '', component: RestaurantsPage, meta: { location: 'Рестораны' }},
{ path: ':restaurantId', component: MapRestaurantsPage, meta: {location: 'Как проехать'}}
] }
];
lengthPath() {
const path = this.$route.path;
return path.split('/').length
}
export default {
computed: {
...mapGetters({
user: 'user'
})
},
methods: {
logOut() {
this.$http.post('logout', { })
.then( response => {
console.log(response);
}, error => {
console.log(error);
});
localStorage.setItem('userAuth', 'no');
this.$router.push('/login')
}
},
beforeRouteEnter(from, to, next) {
const userAuth = localStorage.getItem('userAuth');
//debugger
if (userAuth === "yes") {
next()
} else {
next('/login')
}
}
}
export default {
data() {
return {
user: {
username: '',
password: ''
},
userAuth: ''
};
},
methods: {
logIn() {
this.$http.post('auth', {username : this.user.username, password: this.user.password },{emulateJSON: true})
.then( response => {
this.userAuth = response.body;
if (response.body === 'done') {
localStorage.setItem('userAuth', 'yes')
this.$router.push('/profile')
} else {
}
console.log(response);
}, error => {
console.log(error);
});
}
}
}
path: '/profile', component: ProfilePage requiresAuth: true,