CodeIgniter Forums
Nested routes not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Nested routes not working (/showthread.php?tid=79056)



Nested routes not working - sfarzoso - 04-15-2021

I have defined these routes:

PHP Code:
$routes->group('partner-gestione', function ($routes) {

 
$routes->get('/''Home::management_partner');
 
$routes->get('fiscalita''Home::taxation');
 
$routes->get('entrate-patrimoniali''Home::property_income');
 
$routes->get('valorizzazione-patrimonio''Home::heritage');
 
$routes->get('ottimizzazione-viabilita-urbana''Home::urban');
 
$routes->get('gestione-territorio''Home::territory');
 
$routes->get('catasto-ufficio-tecnico''Home::land_registry');
}); 

when I access to example.com/partner-gestione all works well, but when I try to enter in a nested route like: example.com/partner-gestione/fiscalita I get:

Uncaught SyntaxError: Unexpected token '<'

[Image: ur9VuZ6.png]

if I remove these routes from the group "partner-gestione", everything works fine:

PHP Code:
$routes->get('fiscalita''Home::taxation');
$routes->get('entrate-patrimoniali''Home::property_income');
$routes->get('valorizzazione-patrimonio''Home::heritage');
$routes->get('ottimizzazione-viabilita-urbana''Home::urban');
$routes->get('gestione-territorio''Home::territory');
$routes->get('catasto-ufficio-tecnico''Home::land_registry'); 

how's that possible? Using php spark routes I get:

[Image: A0inray.png]


RE: Nested routes not working - iRedds - 04-15-2021

The problem here is not in routing, but in the wrong paths for loading scripts.


RE: Nested routes not working - sfarzoso - 04-15-2021

(04-15-2021, 06:15 PM)iRedds Wrote: The problem here is not in routing, but in the wrong paths for loading scripts.

All the scripts are loading via CDN. The weird thing is that problem appear only on nested routes on the example above..
You can find the full code hereĀ https://github.com/agungsugiarto/boilerplate/tree/master/src/Views


RE: Nested routes not working - ojmichael - 04-16-2021

All your assets look like they have relative paths, so they're loading via the wrong URL and getting 404. Wrap your CSS and JS files in site_url(); or set a <base href="https://yourdomain.com/> tag in your template.


RE: Nested routes not working - sfarzoso - 04-16-2021

(04-16-2021, 12:03 AM)ojmichael Wrote: All your assets look like they have relative paths, so they're loading via the wrong URL and getting 404. Wrap your CSS and JS files in site_url(); or set a <base href="https://yourdomain.com/> tag in your template.

yeah, thanks to everyone I fixed using:

PHP Code:
<link rel="stylesheet" type="text/css" href="<?= site_url('assets/template/vendor/tiny-slider/tiny-slider.css') ?>"