hi there,
i’m dynamically loading subpages of another page via ajax and a content representation (including a snippet) on the home page, passing the relating subpage-uid via url parameters.
now i redirect the urls like:
config.php
<?php
return [
'debug' => true,
'routes' => function($site) {
return [
[
'pattern' => '(:all)?(:all)',
'action' => function ($slug) {
$data = [
'current' => $slug,
];
if (site()->find($slug)) {
return page('home')->render($data);
} elseif (page('projects/' . $slug)) {
$page = page('projects/' . $slug);
return page('home')->render($data);
} else {
return site()->errorPage();
}
},
// 'filter' => function($slug) {
// if(Str::contains($slug, 'json')) {
// return false;
// }
// }
],
[
'pattern' => '/projects/(:any)',
'action' => function($uid) {
go($uid);
}
]
];
}
];
without ajax, the links do work as intended (and reload the whole page). but after adding the route, the parameters seem to get lost in the get request. how do i bypass the route for json requests? (see commented part)
or am i maybe thinking too complicated? the goal is to simply have projects accessible by url like “example.com/exampleproject” and on ajax load pushstated, so the address bar is always acting “normal” while the page stays the same.
thank you!