2017-02-16 69 views
0

我似乎無法讓我的路線運行...angularjs路線正在改變我的網址

如果我去:http://localhost:8000/#/notes,它改變了我的網址:http://localhost:8000/#!#%2Fnotes。這不起作用:http://localhost:8000/#!#notes

運行angularjs 1.6和路由1.6。我也在使用gulp webserver。

routes.js:

angular.module('NoteWrangler').config(function($routeProvider){ 

    $routeProvider.when('/notes', { 
    templateUrl: '/templates/pages/notes/index.html' 
    }) 

}); 

的index.html:

<div class="wrapper"> 
    <div ng-view> 
    </div> 
</div> 
<script src="/node_modules/jquery/dist/jquery.js" charset="utf-8"></script> 
<script src="/node_modules/angular/angular.js" charset="utf-8"></script> 
<script src="/node_modules/angular-route/angular-route.js" charset="utf-8"></script> 
<script src="app.js"></script> 
<script src="routes.js"></script> 

gulpFile.js

var gulp = require('gulp'); 
var webserver = require('gulp-webserver'); 

gulp.task('webserver', function() { 
    gulp.src('./') 
    .pipe(webserver({ 
     livereload: true, 
     open: true 
    })); 
}); 
+2

只是一個建議,請使用UI路由器。 – pranavjindal999

+0

我猜你的問題是一樣的這個http://stackoverflow.com/questions/41211875/angularjs-1-6-0-latest-now-routes-not-working – Callum

+1

可能重複的[angularjs 1.6.0 (最新現在)路線不工作](http://stackoverflow.com/questions/41211875/angularjs-1-6-0-latest-now-routes-not-working) – Callum

回答

1

你是做正確的,但存在angular 1.6.x的推出改變$locationProvider。在此版本之前,hashprefix的默認值爲空,但現在爲'!'。

檢查https://docs.angularjs.org/api/ng/provider/$locationProvider

https://code.angularjs.org/1.5.11/docs/api/ng/provider/$locationProvider

因此修改route.js如下

angular.module('NoteWrangler').config(function($routeProvider, $locationProvider) { 
 
    $locationProvider.hashPrefix(''); 
 
    //$locationProvider.html5Mode(false); 
 
    //false is default therefore it is not required to set 
 
    $routeProvider.when('/notes', { 
 
    templateUrl: '/templates/pages/notes/index.html' 
 
    }) 
 

 
});