V
V
Valeriy Donika2016-07-21 10:36:33
Angular
Valeriy Donika, 2016-07-21 10:36:33

Angular routeProvider how to optionally specify /page/?

How to make it so that when going to the page /categories/ if this is the first page, then there was no path /categories/page/1 but to /page? will be on the next page.

'use strict';

angular.
module('mainApp').
config(['$locationProvider' ,'$routeProvider',
    function config($locationProvider, $routeProvider) {

        $locationProvider.hashPrefix('!');

        $routeProvider.
        when('/', {
            template: '<home-page></home-page>'
        }).
        when('/categories/page/:page', {
            template: '<category-list categories="$resolve.categories"></category-list>',
            resolve: {
                categories: ['$route', 'Category', function ($route, Category) {
                    return Category.get({page: $route.current.params.page}).$promise;
                }]
            }
        }).
        when('/categories/:slug', {
            template: '<category-detail category="$resolve.category"></category-detail>',
            resolve: {
                category: ['$route', 'Category', function ($route, Category) {
                    return Category.get({slug: $route.current.params.slug}).$promise;
                }]
            }
        }).
        otherwise('/');
    }
]);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question