1. Go to this page and download the library: Download miranj/craft-router library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
miranj / craft-router example snippets
/* config/router.php */
return [
'rules' => [
// URI pattern with named subpatterns
'<section:blog>' => [
'segments' => [
'<year:\d{4}>',
'<category:{slug}>',
'in:<location:{slug}>',
],
// array of filters that are activated when
// the key matches a subpattern variable declared in
// the route's regular expression
'criteria' => [
// Restrict entries to the selected section
'section' => [
'type' => 'section',
],
// Filter entries by year
'year' => [
'type' => 'year',
'field' => 'postDate',
],
// Filter entries by related category
// from the category group with the handle 'travel-styles'
'category' => [
'type' => 'category',
'group' => 'travel-styles',
],
// Filter entries by related entry
// from the section with the handle 'locations'
'location' => [
'type' => 'entry',
'section' => 'locations',
],
],
// template file
'template' => 'blog/_archive',
],
// Site-specific rules can be placed in a sub-array
'siteHandle' => [
'<section:blog>' => …,
],
],
];
'segments' => [
'<year:\d{4}>',
'<category:{slug}>', // eg. budget, luxury, cruise, urban
'in:<location:{slug}>', // eg. asia, europe, australia
]
/*
This will match the following URL suffixes
…/2019
…/2019/budget
…/2019/budget/in:asia
…/2019/in:asia
…/budget
…/budget/in:asia
…/in:asia
Order is relevant, so it will *not* match the following URLs
…/budget/2019
…/in:asia/budget
…/2019/in:asia/budget
*/
'combineSegments' => false
/*
This will match only the following URL suffixes
…/2019
…/budget
…/in:asia
It will *not* match the following URLs
…/2019/budget
…/2019/budget/in:asia
…/2019/in:asia
…/budget/in:asia
*/