Lucky Soni
Lucky Soni

Reputation: 6888

Angular - Not able to respond to the route

When i hit the url http://localhost:8000/something it redirects me to login, why?

Master template:

<!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
    <meta charset="UTF-8">
    <meta name="csrf_token" ng-init="csrf_token='<?php echo csrf_token(); ?>'">


</head>
<body>

    <div ng-view></div>

    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-route.js"></script>
    {{ HTML::script("js/ang/main.js") }}


</body>
</html>

JS:

var app = angular.module('app', ['ngRoute'], function($interpolateProvider) {
    $interpolateProvider.startSymbol('<%');
    $interpolateProvider.endSymbol('%>');
});


app.config(function($routeProvider) {
    $routeProvider
        .when('/something', {
            templateUrl: 'angular_templates/all-timelines.html',
            controller: 'timelinesCtrl'
        })
        .otherwise({
            redirectTo: '/login'
        });

});


app.controller('timelinesCtrl', function($scope, $http) {

});

all-timelines.html

<input type="text">

Upvotes: 0

Views: 87

Answers (1)

mjdwitt
mjdwitt

Reputation: 56

Angular uses hash routes to differentiate between client-side routing and server-side routing. As allenhwkim said in the comments above, $locationProvider.html5Mode(true) will allow you to route with Angular without using hash routes, but this will only work on modern browsers. Your app won't break on older browsers though; they'll just fall back to hash routes.

For example, with html5Mode on, you should be able to route to localhost:8000/something and see your expected Angular view. On an older browser though, you'll have to navigate to localhost:8000/#/something.

See the section on Hashbang and HTML5 Mode in the official Developer Guide.

Upvotes: 1

Related Questions