3 votes

Routing

 

Custom URLs in Umbraco 7 (BETA)


This package allows you to create custom URLS and also change dynamically the template used to render any content node.

 

Roadmap

  • New configuration option to choose which examine index should be used by the routing engine.

  • New configuration options regarding the caching (time in cache, priority, ...)




Installation

Install the package through the backoffice like any other Umbraco package.

The installer will add new dasboard called "Routing" in the developer section of your backoffice

 

Configuration

There are two ways to configure the routes :

  • By using the "Router" dasboard (in the developer section)

  • By editing manually the config file:  ~/config/routing.config


Route parameters:

  • Url Segments [MANDATORY]
    It can contain any number of url segments.
    This parameter cannot be left empty. If it is empty no error will be displayed, but the route will be ignored by the routing engine.


  • Enabled [OPTIONAL]
    Whether the routing engine should process the route.


  • Document Type Alias [OPTIONAL]
    The routing engine will look up only for content nodes that match this Document Type
    If this parameter is left empty then the engine will look up for any content type. If a property name is setup (see below), then only the content types that contains a property with the specified name will be searched.

  • Property Alias [OPTIONAL]
    The routing engine will use the data contained in this property to compare it with the last segment of the request's url
    If this parameter is left empty then the routing engine will display the content node specified in the Fallback NodeId parameter. If the Fallback NodeId parameter is also empty, then this route will be ignored.
    There isn't any restriction regarding the property's datatype. That means that a property specified could contain JSON data for example.

  • Template [OPTIONAL]
    Force Template [OPTIONAL]
    Use the template specified below to display the content node
    This parameter could contain an Umbraco template alias or the full path to the template. i.e. ~/views/home/homepage.cshtml
    If this parameter is left empty then nothing is going to change and the default template assigned through the Umbraco backoffice will be used.
    If the ForceTemplate parameter is true and this property is not empty then this template will be used to display the content node, even if there is already a template assigned.
    If the ForceTemplate parameter is false then this template will be used only in the case that the content node doesn't have any template assigned.

  • Fallback NodeId [OPTIONAL]
    If no content node was found with the previous parameters then it will display the content node specified (could be any document type and not necessarily the one defined in the DocumentTypeAlias parameter)
    If this parameter is left empty then no fallback content will be displayed. That means that if the routing engine doesn't found any content node with this route then it will continue with the following route defined in the config file (if there is any).

  • Description [OPTIONAL]
    This parameter is ignored by the routing engine.



Examples

 

<?xml version="1.0" encoding="utf-8"?><Routes>  <Route UrlSegments="/news/new-version-available/" Enabled="true" DocumentTypeAlias="" PropertyAlias="" Template="" ForceTemplate="false" FallbackNodeId="1380" Description="" />  <Route UrlSegments="/news/you-should-update-asap/" Enabled="true" DocumentTypeAlias="" PropertyAlias="" Template="" ForceTemplate="false" FallbackNodeId="1381" Description="" />  <Route UrlSegments="/contact/" Enabled="true" DocumentTypeAlias="" PropertyAlias="" Template="" ForceTemplate="false" FallbackNodeId="1120" Description="" /></Routes>

This example is a mapping of urls to content nodes.

 

 

<?xml version="1.0" encoding="utf-8"?><Routes>  <Route UrlSegments="/news/international/" Enabled="true" DocumentTypeAlias="newsInternational" PropertyAlias="name" Template="" ForceTemplate="false" FallbackNodeId="1260" Description="" />  <Route UrlSegments="/news/national/" Enabled="true" DocumentTypeAlias="newsNational" PropertyAlias="name" Template="" ForceTemplate="false" FallbackNodeId="1264" Description="" /></Routes>


 http://www.mydomain.com/news/international/this-is-a-news/  => Any content node which name matches "this is a news" and its content type is "newsInternational" will be displayed
 http://www.mydomain.com/news/international/  => The content node which id is 1260 will be displayed
 http://www.mydomain.com/news/international2/ => The routing engine will proceed with the second route since this Url doesn't match with the first rule. The second route doesn't match neither. The default Umbraco routing engine will be used to try to find a content.
 http://www.mydomain.com/news/national/this-is-a-news/ => Any content node which name matches "this is a news" and its content type is "national" will be displayed

 

 

 

 

<?xml version="1.0" encoding="utf-8"?><Routes>  <Route UrlSegments="/news/" Enabled="true" DocumentTypeAlias="newsInternational" PropertyAlias="newsTitle" Template="" ForceTemplate="false" FallbackNodeId="" Description="" />  <Route UrlSegments="/news/" Enabled="true" DocumentTypeAlias="newsNational" PropertyAlias="newsTitle" Template="" ForceTemplate="false" FallbackNodeId="" Description="" />  <Route UrlSegments="/news/" Enabled="true" DocumentTypeAlias="" PropertyAlias="" Template="" ForceTemplate="false" FallbackNodeId="1364" Description="" /></Routes>

 

http://www.mydomain.com/news/this-is-a-news/ => Any content node which name matches "this is a news" and its content type is "newsInternational" or "newsNational" will be displayed
 http://www.mydomain.com/news/ => The content node which id is 1364 will be displayed

 

 

 

Updates

  • v0.2.1 [2015-04-06]
    - Remove properly all files when uninstalling 

 

  • v0.1.0 [2015-02-08]  
     - Initial release

 

 

 

 

 

Screenshots

Package owner

Alain

Alain

Alain has 520 karma points

Package Compatibility

This package is compatible with the following versions as reported by community members who have downloaded this package:
Untested or doesn't work on Umbraco Cloud
8.4.x (untested)
8.3.x (untested)
8.2.x (untested)
8.1.x (untested)
8.0.x (untested)
7.15.x (untested)
7.14.x (untested)
7.13.x (untested)
7.12.x (untested)
7.11.x (untested)
7.10.x (untested)
7.9.x (untested)
7.8.x (untested)
7.7.x (untested)
7.6.x (untested)
7.5.x (untested)
7.4.x (untested)
7.3.x (100%)
7.2.x (100%)
7.1.x (100%)
7.0.x (untested)
6.1.x (untested)
6.0.x (untested)

You must login before you can report on package compatibility.

Package Information

  • Package owner: Alain
  • Created: 08/02/2015
  • Current version 0.2.1
  • License MIT
  • Downloads: 1651

External resources