简体   繁体   English

durandal中路线起点的参数

[英]Parameter at beginning of route in durandal

The typical route in Durandal looks like: 杜兰达尔的典型路线如下:

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

Id - http://mysite.com/#/Person/123 (Person/:id) Id - http://mysite.com/#/Person/123 (人/: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://durandaljs.com/documentation/Router/我需要覆盖以支持这样的事情:

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

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

How would I implement something like this? 我该如何实现这样的东西?

You answered your own question. 你是在自问自答。 To implement http://mysite.com/#/abc123/Home you have to define a route that models that, for example: 要实现http://mysite.com/#/abc123/Home,您必须定义一个对其进行建模的路由,例如:

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. 当有人前往您的路线时,它将导航到您的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). 请记住,路由器将首先导航到最简单的路由,因此请正确排序(例如,如果您将router.mapRoute('','viewmodels / home','home view')作为第一条路由,路由器将始终转到此路由,而不是在其路由器队列中进一步查看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM