Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addRoute implemented #7

Merged
4 commits merged into from
Dec 21, 2010
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,19 @@ You can use regular expressions as well. This leads myapp.com/register to your U
Ni.addRoute(/^\/register/i, '/User/register');

If you want to use arguments with custom routes, you can do that as well:
Ni.addRoute(/^\/details\/([\d]+)/i, '/User/details/$1');
Ni.addRoute(/^\/details\/(.*)$/i, '/User/details/$1');

You can also define functions to test the path. This example will add the first and second path variables.
Calling myapp.com/1/2 will internally redirect to use the "Number" controller and call the "positive" function, while calling myapp.com/1/-2 will call the "negative" function.
You can also define functions to test the path. For example:
Calling myapp.com/add/1/2 will internally redirect to use the "Number" controller and call the "positive" function, while calling
myapp.com/add/1/-2 will call the "negative" function.
Ni.addRoute(function(path) {
var args = path.split('/'),
firstNum = parseInt(args[1]),
secondNum = parseInt(args[2]),
firstNum = parseInt(args[2]),
secondNum = parseInt(args[3]),
result = firstNum + secondNum;
return result > 0 ? '/Number/positive' : '/Number/negative'; // returning false would leave the path untouched
if (args[1] !== 'add')
return false; // this leaves the path untouched and prevents this function from sucking in all other requests as well
return result > 0 ? '/Number/positive' : '/Number/negative';
});

You can limit the allowed HTTP methods by using custom routes.
Expand Down