使用来从URL获取参数
ngRoute。这意味着您将需要在应用程序中包含 angular-
route.js
作为依赖项。有关更多信息,请参见ngRoute官方文档。
问题的解决方案:
// You need to add 'ngRoute' as a dependency in your appangular.module('ngApp', ['ngRoute']) .config(function ($routeProvider, $locationProvider) { // configure the routing rules here $routeProvider.when('/backend/:type/:id', { controller: 'PagesCtrl' }); // enable HTML5mode to disable hashbang urls $locationProvider.html5Mode(true); }) .controller('PagesCtrl', function ($routeParams) { console.log($routeParams.id, $routeParams.type); });如果您未启用
$locationProvider.html5Mode(true);。Urls将使用hashbang(
/#/)。
有关路由的更多信息,请参见正式的angular $ route
API文档。
旁注: 这个问题正在回答如何使用ng-Route实现此目的,但是我建议使用 ui-Router 进行路由。它更灵活,提供更多功能,文档很棒,并且被认为是最佳的角度布线库。



