2016-04-05 6 views
1

Ich bin neu in angularJs. Ich habe gerade versucht, Seiten in eckigenJs zu routen. Es funktioniert, aber das '#' Symbol wird angezeigt. Also ich habeEntfernen Hashbang von URL in AngularJs Route

$locationProvider and $locationProvider.html5Mode(true); 

verwendet, aber es funktioniert nicht. Also gebe ich meinen Code, um nach Hilfe zu suchen, um das Problem zu finden. Ich benutze CDN von angularJs.

Die Projektstruktur ist:

enter image description here

app.Js Datei ist

'use strict'; 

angular.module('myApp', ['myApp.controllers', 'ngRoute']); 

angular.module('myApp').config(function ($routeProvider, $locationProvider) { 
    $routeProvider 
     .when('/view1', { 
      controller: 'Controller1', 
      templateUrl: 'partials/view1.html' 
     }) 
     .when('/view2', { 
      controller: 'Controller2', 
      templateUrl: 'partials/view2.html' 
     }); 

    $locationProvider.html5Mode(true); //activate HTML5 Mode 
}); 

Controller ist:

'use strict'; 

angular.module('myApp.controllers', []) 
    .controller('Controller1', function ($scope) { 
     $scope.message = "Hello, world"; 
    }) 
    .controller('Controller2', function ($scope) { 
     $scope.now = new Date(); 
    }); 

HTML-Seite:

<!doctype html> 
<html lang="en" ng-app="myApp"> 
<head> 
    <meta charset="utf-8"> 
    <title>AngularJS Routing</title> 
    <link rel="stylesheet" href="app.css"/> 
    <base href="/"> 
</head> 
<body> 
<ul class="menu"> 
    <li><a href="/view1">view1</a></li> 
    <li><a href="/view2">view2</a></li> 
</ul> 
<ng-view></ng-view> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-route.js"></script>  
<script src="app.js"></script> 
<script src="controllers.js"></script> 
</body> 
</html> 

Antwort

2

Ihre Basis sollte Ihr Projektordnerpfad sein. In Ihrem Fall

<base href="/untitled1/"> 

Auch hoffe ich Ihnen die Aktualisierung der Seite Umleitung durch .htaccess für Ihr Feedback

Siehe this link für weitere Informationen in diesem

+0

Dank umgehen. aber es funktioniert nicht. zeigt immer noch 404 Nicht gefunden. Glauben Sie, dass mit der CDN-Version etwas nicht stimmt? –