2016-05-16 11 views
0

創建$狀態中的網址我想創建像一個URL: '?'如何angularjs

http://localhost:3000/home/#/student/studentId=63

http://localhost:3000/home/#/student:studentId=63

不使用字符。

但下面的代碼也沒有創造像以上這樣的一個網址:

http://localhost:3000/home/#/student?studentId=63

.state('home.student', { 
     url: 'student/:courseId/:studentId/', 
     controller: 'StudentController', 
     templateUrl: 'student.view.html', 
     }) 

這種狀態創建網址像 :

.state('home.student', { 
     url: 'student?courseId&studentId', 
     controller: 'StudentController', 
     templateUrl: 'student.view.html', 
     }) 

這個國家創造像一個URL http://localhost:3000/home/#/student/63

可能有人請告訴我如何建立像網址: '?'

http://localhost:3000/home/#/student/studentId=63

http://localhost:3000/home/#/student:studentId=63

在上述網址字符不是必需的。

+1

爲什麼要創建這樣的非標準URL?你可能需要做很多額外的工作。順便說一句,你說的是* ui-router *,對嗎? – stholzm

+0

[我認爲你的答案寫在那裏](http://stackoverflow.com/questions/33181532/why-give-an-abstract-true-state-a-url) –

回答

0

url就像是一個模式,所以只寫你想要的圖案。對於[your base url for the 'home' state]/student/studentId=63

$stateProvider.state('home.student', { 
    url: '/student/studentId=:studentId', 
    controller: 'StudentController', 
    templateUrl: 'student.view.html', 
})