Uncheck tag filters

Hi
I would like to uncheck tag when one of these is active. For example, on ..../tag:IN%2BSITU/date:current, when date tag is clicked again, the url would be : .../tag:IN%2BSITU only, in order to uncheck date.

My controller :

<?php

return function ($site, $kirby, $pages, $page) {

   $query   = get('q');
   $results = $site->search($query, 'title|text|title_notice|domain|description');


   $articlesexpo = $site->find('expositions')->children()->listed()->sortBy('datedebut', 'desc');

   if($tagexpo = urldecode(param('tag'))) {
      $articlesexpo = $articlesexpo->filterBy('tags', $tagexpo, ',');
   }

   if($datetag = urldecode(param('date'))) {
      $articlesexpo = $articlesexpo->filter(function($item) use($datetag) {
         if ($datetag === 'future') {
            return $item->datedebut()->toDate() > time();
         }
         if ($datetag === 'passe') {
            return $item->datefin()->toDate() < time();
         }
         if ($datetag === 'current') {
            return $item->datedebut()->toDate() <= time() && $item->datefin()->toDate() >= time();
         }
         return $item->datedebut()->toDate('Y') === $datetag;
      });
   }
   
   $tagsexpo = $articlesexpo->pluck('tags', ',', true);
   $collator = new Collator('fr_FR');
   $collator->sort($tagsexpo);
   
   $articlesexpo   = $articlesexpo->paginate(5);
   $paginationexpo = $articlesexpo->pagination();

   return [

      'articlesexpo' => $articlesexpo,
      'tagsexpo' => $tagsexpo,
      'tagexpo' => $tagexpo,
      'paginationexpo'   => $paginationexpo,
      'datetag' => $datetag,
      'query'   => $query,
      'results' => $results,
   ];

};

my template :

 <ul>
         
         <li>
            <a class="<?= param('date') == 'future' ? 'active' : '' ?>" href="<?= url($page->url(), ['params' => array_merge(params(),['date' => 'future']) ]) ?>"><?= t('avenir') ?></a>
         </li>
         <li>
            <a class="<?= param('date') == 'current' ? 'active' : '' ?>" href="<?= url($page->url(), ['params' => array_merge(params(),['date' => 'current']) ]) ?>"><?= t('encours') ?></a>
         </li>
         <li>
            <a class="<?= param('date') == 'passe' ? 'active' : '' ?>" href="<?= url($page->url(), ['params' => array_merge(params(),['date' => 'passe']) ]) ?>"><?= t('passe') ?></a>
         </li>

         <?php foreach($tagsexpo as $tag): ?>
         <li>
            <a <?php e($tag === urldecode(param('tag')), 'class="active"', '')  ?> href="<?= url($page->url(), ['params' => array_merge(params(),['tag' => urlencode($tag)]) ]) ?>">
               <?= html($tag) ?>
            </a>
         </li>
         <?php endforeach ?>
      </ul>

For each of the params, you already check if it is set to add the active class. The same logic you would apply to determining if you need to unset the parameter from params() and in that case not merge.

Thanks !

This was, as you said, a lack of conditions for each of links.

 <ul>

         <?php if(param('date') == 'future'): ?>
         <li>
            <a class="<?= param('date') == 'future' ? 'active' : '' ?>" href="<?= url($page->url(), ['params' => ['tag' => urlencode($tag)]]) ?>">× <?= t('avenir') ?></a>
         </li>
         <?php else: ?>
         <li>
            <a class="<?= param('date') == 'future' ? 'active' : '' ?>" href="<?= url($page->url(), ['params' => array_merge(params(),['date' => 'future']) ]) ?>"><?= t('avenir') ?></a>
         </li>
         <?php endif ?>


         <?php if(param('date') == 'current'): ?>
         <li>
            <a class="<?= param('date') == 'current' ? 'active' : '' ?>" href="<?= url($page->url(), ['params' => ['tag' => urlencode($tag)]]) ?>">× <?= t('encours') ?></a>
         </li>
         <?php else: ?>
         <li>
            <a class="<?= param('date') == 'current' ? 'active' : '' ?>" href="<?= url($page->url(), ['params' => array_merge(params(),['date' => 'current']) ]) ?>"><?= t('encours') ?></a>
         </li>
         <?php endif ?>

         <?php if(param('date') == 'passe'): ?>
         <li>
            <a class="<?= param('date') == 'passe' ? 'active' : '' ?>" href="<?= url($page->url(), ['params' => ['tag' => urlencode($tag)]]) ?>">× <?= t('passe') ?></a>
         </li>
         <?php else: ?>
         <li>
            <a class="<?= param('date') == 'passe' ? 'active' : '' ?>" href="<?= url($page->url(), ['params' => array_merge(params(),['date' => 'passe']) ]) ?>"><?= t('passe') ?></a>
         </li>
         <?php endif ?>

         <?php $i = 0;foreach($tags as $tag): ?>
         <?php if($tag == urldecode(param('tag'))): ?>
         <li <?php if($i++ == 0): ?>class="tag"<?php endif ?>>
            <a <?php e($tag === urldecode(param('tag')), 'class="active"', '')  ?> href="<?= url($page->url(), ['params' => ['date' => urlencode($datetag)]]) ?>">
               × <?= html($tag) ?>
            </a>
         </li>
         <?php else: ?>
         <li <?php if($i++ == 0): ?>class="tag"<?php endif ?>>
            <a <?php e($tag === urldecode(param('tag')), 'class="active"', '')  ?> href="<?= url($page->url(), ['params' => array_merge(params(),['tag' => urlencode($tag)]) ]) ?>">
               <?= html($tag) ?>
            </a>
         </li>
         <?php endif ?>
         <?php endforeach ?>
      </ul>