1

I have the following routes:

/**
 * General app route
 */
angular
    .module('app')
    .config(config);

config.$inject = ['$routeProvider', '$locationProvider'];
function config($routeProvider, $locationProvider) {
    $routeProvider
        .when('/', {
            templateUrl: 'partials/index.html',
            controller: 'ImageController'
        })
        .when('/category/:name', {
            templateUrl: 'partials/index.html',
            controller: 'CategoryController',
        })
        .when('/404', {
            templateUrl: 'partials/404.html'
        })
        .otherwise({ redirectTo: '/404' });

    $locationProvider.html5Mode({
        enabled: true,
        requireBase: false
    });
}

when I'm trying to access the category route from base route it works fine, but when I reload the page on category route it tries to access the assets file through category path instead of base path. how can I fix it?

3 Answers 3

1

I figured it out by adding base tag to index.html

<head>
    <base href="/index.html">
</head>
Sign up to request clarification or add additional context in comments.

Comments

0

One way is the disable HTML5 mode

$locationProvider.html5Mode({
    // enabled: true,
    requireBase: false
});

Other way is to make sure the server side routing returns correct HTML file.

1 Comment

Thanks for your answer, you're solutions works but I added html5mode for removing # from url.
0

You have activate html5 mode, and for that you need redirect all the traffic to the index.html

See the section html5 mode for more details https://docs.angularjs.org/guide/$location

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.