I am new to AngularJS, so forgive me if this is obvious, but I am looking for someone who can answer this tricky question. I am implementing an application, and need to pass some parameters to a particular view to display details about a book. Basically I would like to be able to use the following routing expressions:
bookApp.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/catalog', {
templateUrl: 'cataloglist.htm',
controller: 'catCtrl'
}).
when('/book/:title/:chapter', {
template: 'chapterdetail.htm',
controller: 'chapterCtrl'
}).
otherwise({
template: 'oops ... do not understand that route',
});
}]);
The expression /book/:title/:chapter
should allow me to pass in the name of the title of a book. I am expecting to be able to pass ANY title of any book in there. To make sure that things are properly delimited, I am going to URL encode the title value, so that in the encoded value there will be no slashes and the value will be clearly delimited by the slash characters. This is the normal way to construct URLs that contain values.
The problem is that there exist book titles that contain the slash character (e.g. The 3/5 solution
) This is URL encoded as The+3%2F5+Solution
. So can construct a URL like this:
/app/#/book/The+3%2F5+Solution/The%20Beginning
However, my experience seems to show that the entire value is URL decoded BEFORE it is broken into parameters! This means that any data value with a slash in it, will be misinterpreted as two values, and the pattern matching of the route parameters is broken, and only the first half of the value is passed in. Furthermore, the chapter might have a slash in the name as well.
If I was making a REST service, I would URL encode the value, and the URL will be parsed into pieces BEFORE each piece is decoded. For example, I can use query parameters in a URL like this:
app.jsp?title=The+3%2F5+Solution&chapter=The%20Beginning
and this will work correctly. Using URL encoding, I can pass ANY string value in the title. I would have expected route parameters to do the same thing ... but I already mentioned I am NEW to AngularJS.
To decode the %2F
into a slash BEFORE determining the pieces seems like a very serious bug. Apparently, you simply can't pass values with a slash in them as route parameters. Am I missing something here? What is the solution to allow me to safely pass a book name with ANY possible character in it (along with a chapter title with ANY character in it), as a route parameter?
/foo-man-chu
but the ajax request uses its dewey(sic) decimal system number. remember that you have all the book data available in an object in your scope – Loma