簡體   English   中英

如何在angularjs,ui-router和$ stateParams中使用url參數

[英]How to use url parameters in angularjs, ui-router and $stateParams

我已經按照https://github.com/angular-ui/ui-router/wiki/URL-Routing中的說明進行操作,但是無法使其正常工作。

我有以下內容:

var application = angular.module('application', ['ui.router']);

application.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
$urlRouterProvider.otherwise("/test");

$stateProvider
    .state('index', {
        url: "/test/:param",
        templateUrl: "App/Test.html", 
        controller: function ($scope, $stateParams) {
            alert($stateParams.param);
        }
    });   

$locationProvider.html5Mode(true);
});

沒有/:param,它將按您期望的那樣工作-即ui-view正確地填充了Test.html。 但是,每當我將/:param放入時,都會出現錯誤。 錯誤是:

GET http://localhost:3880/test/App/Test.html 404 (Not Found)

應用程序是我的棱角分明的東西的路線,並且Test.html應該具有以下路徑

http://localhost:3880/App/Test.html 

如果不嘗試/:param,它會這樣做。 但是,在嘗試/:param時,您會看到/ App之前的路徑中還有一個額外的/ test /。

請有人幫忙,因為我想在控制器正確后使用該參數。

您用於此路由的URL應該是這樣的: http://localhost:3880/test/app其中app是param。

為templateUrl使用絕對路徑。 相對網址不會起作用。

templateUrl: "/path/to/App/Test.html",

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM