diff --git a/module/VuFind/src/VuFind/Hierarchy/TreeRenderer/JSTree.php b/module/VuFind/src/VuFind/Hierarchy/TreeRenderer/JSTree.php
index d51686756fbd59189963e2ef656c7705c26cf506..c1fb104367c8cab650f04a9ebef94495003e6aba 100644
--- a/module/VuFind/src/VuFind/Hierarchy/TreeRenderer/JSTree.php
+++ b/module/VuFind/src/VuFind/Hierarchy/TreeRenderer/JSTree.php
@@ -251,7 +251,7 @@ class JSTree extends AbstractBase
             ];
             $cache[$route] = $this->router->fromRoute($route, $params, $options);
         }
-        return str_replace('__record_id__', $id, $cache[$route]);
+        return str_replace('__record_id__', urlencode($id), $cache[$route]);
     }
 
     /**