Tags on the routed url

Hello, I have a question about putting tags on the routed url.
It means I re-routed the url without ‘home/’.
ex) home/text → /text

And then, after I put tags on the page called ‘home/texts/text’, I can see titles of tags but when I click it, the url goes to error page. So that I couldn’t see that the text list is categorized by tags.
Do you know how can I edit these code for this issue?
Thank you:)

on config.php

c::set('routes', array(
	array(
		'pattern' => '(:any)',
		'action'  => function($uid) {
			$page = page($uid);
			if(!$page) $page = page('home/' . $uid);
			if(!$page) $page = page('home/press/' . $uid);
			if(!$page) $page = site()->errorPage();
			return site()->visit($page);
		}
	),
	array(
		'pattern' => ['home/(:any)', 'home/press/(:any)'],
		'action'  => function($uid) {
			go($uid);
		}
	)
));

on controllers/text/php

<?php

return function ($page) {

  $textcategory = param('textCategory');
  $textslist = page('home/press/texts')->children()->listed();
  $textcategories = $textslist->pluck('textCategory', ',', true);
  
  $textslist =  $textslist
      ->when($textcategory, function ($textcategory) {
          return $this->filterBy('category', $textcategory, ',');
      });
      

  return compact('textslist', 'textcategories');

};

on text.php

  <ul class="filter--category">
    <?php foreach ($textcategories as $textcategories): ?>
      <li>
        <a href="<?= $page->parent()->url(['params' => ['textCategory' => $textcategories]]) ?>"><?= html($textcategories) ?></a>
      </li>
      <?php endforeach ?>
  </ul>

Here you get try to get a page called home/press/texts, but this URL is not in your redirect routing patterns?

You mean the code page('home/press/texts') on controllers/text.php?
Sorry, I mistyped on config.php for this question.
Could you check my codes again if there is something wrong to get tags?
Thanks

This url is not correct, because you are redirecting all pages under home to the root. So you either use $site->url() . '/' . $page->slug() . '/textCategory:' . $textCategory. Or you overwrite the url() method in a page model (which would be the preferred way anyway, so that the new url is used everywhere and the redirect wouldn’t have to kick in).

1 Like

Thanks a lot:) Now I can get the proper url for tags but the list in html doesn’t change following the categorized url.
I checked the codes and tried to change some, but doesn’t work… Do you have any idea about this?

I’ve somehow lost track of what you have changed now and what doesn’t work.

Sorry, I checked the code and found I didn’t put <?php foreach ($textslist as $tlist): ?> on texts.php.
This is awesome! Thank you so much, Sonja:)