ForgeTotal.js 5
en

Total.js 5

Read URL parameters in a route

Total.js 5 · total5@0.0.19 routingparams Executed against Total.js 5

Wrap a segment of the URL in curly braces and Total.js exposes its value in $.params. A route can contain as many parameters as you need.

controllers/users.js
exports.install = function() {
	ROUTE('GET /users/{id}/', show_user);
	ROUTE('GET /users/{id}/posts/{post}/', show_post);
};

function show_user($) {
	$.json({ id: $.params.id });
}

function show_post($) {
	$.json({ id: $.params.id, post: $.params.post });
}

$.json() sends the value as JSON. Parameters are always strings; validate or convert them yourself, or declare their types in an action (see the actions recipe).