0
votes

I'm developing a webapp using AngularJS and Laravel.

When I navigate through URL and links in the app everything works fine, but if I type an URL directly in the browser, something strange happens.

For example, If I type http://myapp.dev/#/customers I get redirected to http://myapp.dev/customers#/

Why? What's wrong? Laravel executes "/" route (right) and Angular "/" route (right, again).

Note: I have made a test application similar to the first but without using Laravel and .htaccess (it serves only static HTML) and I haven't this issue, I can access URL directly.

Thank you.

Edit - here the Angular routing code:

var App = angular.module('Factotum', ['ngResource']);

function appRouteConfig($routeProvider) {
    $routeProvider.

    when('/', {
        controller: IndiceController,
        templateUrl: 'v/indice'
    }).
    when('/login', {
        controller: 'AppController',
        templateUrl: 'v/login'
    }).
    when('/logout', {
        controller: 'AppController',
        templateUrl: 'v/login'
    }).
    // ---- Clienti
    when('/clienti', {
        controller: ClientiController,
        templateUrl: 'v/clienti/lista'
    }).
    when('/clienti/nuovo', {
        controller: ClientiController,
        templateUrl: 'v/clienti/nuovo'
    }).
    when('/clienti/modifica/:id', {
        controller: ClientiController,
        templateUrl: 'v/clienti/modifica'
    }).
    // ---- Progetti
    when('/progetti', {
        controller: ProgettiController,
        templateUrl: 'v/progetti/lista'
    }).
    when('/progetti/nuovo', {
        controller: ProgettiController,
        templateUrl: 'v/progetti/nuovo'
    }).
    otherwise({
        redirectTo: '/'
    });
} // factotumRouteConfig

App.config(appRouteConfig);
1
Edit: If I browse to myapp.dev/#customers I get redirected to myapp.dev/#/customers (ok) - eleftrik
are you using angular's html5Mode? - Ven
can you show your routing code ? - Tasnim Reza
@user1737909: No, html5Mode is off. - eleftrik
@Reza Do you mean Angular routing code? I've pasted it in the post. Thanks - eleftrik

1 Answers

2
votes

Finally I found the problem. I'm using a free HTML5 template (Charisma by Usman - here a demo: http://usman.it/themes/charisma/), which includes jQuery History plugin. I removed this plugin, along with some initialization code, and now all is working as expected. My fault, I didn't inspect the code carefully.