Every page in DotVVM needs to be registered in the route table. DotVVM doesn't allow visiting a page just by putting its path in the URL.
The routes are configured as part of the configuration in the DotvvmStartup
class.
Register routes one by oneTo separate the configuration options, the default project templates contain
ConfigureControls
,ConfigureRoutes
andConfigureResources
methods, which are called from theConfigure
method. You can use any structure you like - the only requirement is that theConfigure
method performs all the configuration actions.
In simple web applications, you can register each route individually using the following code snippet:
config.RouteTable.Add("Page", "my/page/url", "Views/page.dothtml", new { });
The first argument is the name of the route. You'll need it when you do redirects, or generate a hyperlink that navigates the user to this page (e. g. using the RouteLink control). This name is not displayed to the user, it is only a string which identifies the route in the application code.
The second argument is the route URL. It can contain route parameters (e.g. "product-detail/{ProductId}"
) which you can retrieve in the viewmodel when the page is loaded. For the default page, you can use ""
as the route URL.
The third argument is the location of the .dothtml
file which will be used to handle the request. Because the file doesn't have to be in the Views folder, you need to pass an application relative path including the Views
folder name: Views/page.dothtml
.
The fourth argument (optional) specifies default values for route parameters. If the parameter value is not specified in the URL, the value from this object will be used. You can pass an anonymous object with property names that correspond with the route parameter names, or IDictionary<string, object>
.
If you have several similar routes, you can register them as a group:
config.RouteTable.AddGroup("Admin", "admin", "Views/Admin", table =>
{
table.Add("Customers", "customers", "Customers.dothtml");
table.Add("Customer", "customer/{id}", "Customer.dothtml");
});
The AddGroup
method allows specify a common prefix for all the routes. The routes will be registered according to the following table:
Admin_Customers
admin/customers
Views/Admin/Customers.dothtml
Admin_Customer
admin/customer/{id}
Views/Admin/Customer.dothtml
As you can see, the route name, route URL, and dothtml
file location are composed from the AddGroup
method parameters and the parameters of the particular route. Notice that the _
character is added between the group name and route name. Route URL and file location are treated like paths and joined by /
.
If you need to register a route which should not be treated as .dothtml
file, e.g. if you need a handler that serves files, generates RSS feeds or anything like that, you can declare a custom presenter and specify a method, that creates an instance of it, as the fifth parameter.
If you change the URLs in your app, you can use redirection routes to preserve the old URLs.
Using RouteLink to create links between pagesIf you have a larger project, you may want to use conventions to auto-discover routes instead of registering them one by one.
To create hyperlinks to DotVVM pages, it is recommended to use the RouteLink
controls:
<dot:RouteLink RouteName="ArticleDetail"
Param-Id="{value: CurrentArticleId}"
Param-Title="{value: CurrentArticleTitle}" />
The route parameters can be specified using properties starting with Param-
. If the parameter is not specified, and the current page has a parameter with the same name, the value from the current page will be used.
If the current page doesn't have this parameter, the default value from the route will be used. If no default value for the parameter is not specified, an empty string will be substituted for this parameter.
Redirect to another routeIf you want to redirect the user to another page from the viewmodel code, you can call Context.RedirectToRoute("routeName", new { Param1 = param... })
.
plane github videos sample theme academy controls tutorial twitter facebook search list
Information about cookiesWe use cookies to analyze our traffic, personalize content and ads, and to provide some social media features. We also share information about your use of our site with our social media, advertising and analytics partners who may combine it with other information that you've provided to them or that they've collected from your use of their services.
Choose which cookies you want to enable Necessary cookies Always allowedNecessary cookies are essential and maintain information based on your activity on our site, like remembering your signed in account, selection of your language, or products added to the shopping cart. The website cannot work properly without these cookies.
Google AnalyticsWe use these cookies to measure, collect, analyse and report how users interact with our sites to better understand their behavior. Thanks to this, we can improve the site and provide better experience. The analytics service is provided by Google Inc.
Google AdsWe use these cookies to measure conversions from our advertisement and banners distributed via Google Ads. This allows us to better target the ads and make them more relevant to you.
Facebook PixelWe use these cookies to measure conversions from our advertisement and banners distributed via Facebook. This allows us to better target the ads and make them more relevant to you.
SmartlookWe use these cookies to measure, collect, analyse and report how users interact with our sites to better understand their behavior. Thanks to this, we can improve the site and provide better experience. The analytics service is provided by Smartlook.
Google ads user data Google ads ad personalizationRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4