【发布时间】:2017-08-10 07:18:11
【问题描述】:
我想在我的网站中创建动态 URL。我在前端使用 Angular 和 ngRoute。我基本上想要这个网址:
mysite.com/home
mysite.com/about
mysite.com/(电台名称)/ - 这是我创建的每个电台的页面
但是当我访问像 whateverUrl 这样的电台页面时,我得到了错误:
无法获取 /whateverUrl/
我尝试创建类似 /station/whateverURL 的路线并且成功了!但我希望 URL 尽可能短。
我的代码如下:
angular.module("app").config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
var apiVersion = "/api/v2/";
$routeProvider.when("/", {
templateUrl: "/static/app/view/home.html",
controller: "HomeController",
resolve: {
userData: function(commonService) {
return commonService.get(apiVersion + "users/");
}
}
}).when("/home/", {
templateUrl: "/static/app/view/home.html",
controller: "HomeController",
resolve: {
userData: function(commonService) {
return commonService.get(apiVersion + "users/");
}
}
}).when("/about/", {
templateUrl: "/static/app/view/about.html"
}).when("/:stationId/", {
templateUrl: "/static/app/view/station.html",
controller: "StationController",
resolve: {
stationData: function(commonService, $route) {
return commonService.get(apiVersion + "stations/" + $route.current.params.stationId + "/");
}
});
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
}]);
【问题讨论】:
标签: angularjs django url routes ngroute