CodeIgniter Forums
Route to named anchor - #anchor - is it possible? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Route to named anchor - #anchor - is it possible? (/showthread.php?tid=34630)



Route to named anchor - #anchor - is it possible? - El Forum - 10-05-2010

[eluser]Flemming[/eluser]
this may be a ridiculous question but is it possible to use routes with named anchors?

I have a really long page in my project with named anchors, and a 'jump to' menu at the top of the page.

I'm also linking to these named anchors from my footer file (on every page) like so:

Code:
<a href="/services#advertising">advertising</a>
<a href="/services#brand">brand</a>
and so on.

From my footer it would be great if I could link to :
Code:
<a href="/services/advertising">advertising</a>

and reroute these to the named anchors. In routes.php I tried
Code:
$route['services/advertising'] = "services#advertising";

but I just get a 404.


Route to named anchor - #anchor - is it possible? - El Forum - 10-05-2010

[eluser]pkrstic[/eluser]
Named anchors cannot be transfered to php, one solution is to save them in cookie with javascript and then jump to link. If you don't use ajax on front then avoid named anchors.


Route to named anchor - #anchor - is it possible? - El Forum - 10-05-2010

[eluser]pickupman[/eluser]
Instead of using routes what happens when use a rule htaccess instead. You may have to craft you regex to make it work.


Route to named anchor - #anchor - is it possible? - El Forum - 10-05-2010

[eluser]jmadsen[/eluser]
you might try also making your anchor tags "false" and having js handle the click with a [removed].

You can write that with a single class name and generic js function that could be used throughout your site.


Route to named anchor - #anchor - is it possible? - El Forum - 10-06-2010

[eluser]Fireclave[/eluser]
you could use the third parameter for this problem

$route['controller/method/([a-z]+)'] and the third could be the anchor

take a look here http://ellislab.com/codeigniter/user-guide/general/routing.html