Jason More
Jason More

Reputation: 7073

Parameter at beginning of route in durandal

The typical route in Durandal looks like:

Regular - http://mysite.com/#/Home

Id - http://mysite.com/#/Person/123 (Person/:id)

I'm trying to figure out which method(s) I need on http://durandaljs.com/documentation/Router/ I need to overwrite to support something like this:

http://mysite.com/#/Abc123/Home (:siteId/Home)

http://mysite.com/#/Abc123/Person/123 (:siteId/Person/:id)

How would I implement something like this?

Upvotes: 0

Views: 1397

Answers (1)

RyanKeeter
RyanKeeter

Reputation: 6139

You answered your own question. To implement http://mysite.com/#/abc123/Home you have to define a route that models that, for example:

var router = require('durandal/plugins/router');
router.mapRoute('#/:sideId/home','viewmodels/customViewModel','This is the title of the view');

when someone goes to your route, it will navigate to your customViewModel.

Just remember, that the router will navigate to the easiest route first, so order them correctly (for example, if you have router.mapRoute('','viewmodels/home','home view') as your first route, the router will always go to this route, and not read look further in its router queue).

Upvotes: 2

Related Questions