A
A
Alexander2016-01-14 22:11:09
JavaScript
Alexander, 2016-01-14 22:11:09

Doesn't work otherwise in $routeProvider?

var app = angular.module('Application', ['ngRoute']);
app.config(function ($routeProvider, $locationProvider) {
    $locationProvider.html5Mode(true);
    $routeProvider
        .when('/', {
            controller: 'MainCtrl',
            templateUrl: 'views/app.html'
        })
        .when('/photo/:id', {
            controller: 'PhotoCtrl',
            templateUrl: 'views/photo.html'
        })
        .otherwise({
            redirectTo: '/'
        });
});

When I type in the browser angular.local/asdasdasd I get an error:
"Object not found!".
why is there no redirect to "/"?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Kondaurov, 2016-01-14
@kondaurov

I don't use ngRouter, I use ui-router.
Everything seems to be correct with the provider
. It seems to me that the hash tag in the url is missing, it's js, it can only work with them. What will be easy if you go to angular.local?

_
_ _, 2016-01-15
@AMar4enko

Enabling html5 mode in Angular is not enough, you also need to configure the server so that it always returns index.html for any link

N
nk_pl, 2016-01-18
@nk_pl

$locationProvider.hashPrefix('#');
and <base href="/" />in the head section

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question