I am using the SiteMapModule, so it will be a little different for you, but in the module, there is a makeChildList function for creating the nested links. I passed an additional parameter to this function for the parent page's url, which I called $parentURL which I amended to the beginning of the href tag as shown below:
private function makeList($pages) {
$output = "";
if(count($pages)) {
$output = '
<ul id="sitemap-list">';
foreach($pages as $page) {
if(!($page instanceof ErrorPage) && $page->ShowInMenus && $page->Title != $this->Title){
$output .= '
<li><a href="'.$page->URLSegment.'" title="Go to the '.Convert::raw2xml($page->Title).' page">'.Convert::raw2xml($page->MenuTitle).'</a>';
$whereStatement = "ParentID = ".$page->ID;
//$childPages = new DataObjectSet();
$childPages = DataObject::get("Page", $whereStatement);
$output .= $this->makeChildList($childPages, $page->URLSegment);
$output .= '
</li>';
}
}
$output .= '
</ul>';
}
return $output;
}
private function makeChildList($pages, $parentURL) {
$output = "";
if(count($pages)) {
$output = '
<ul>';
foreach($pages as $page) {
/* if selected, check if user has permission to view page and skip rendering it if they don't have permission. */
if (self::$siteMapPermissionCheck) {
if (!$page->canView()) {
continue;
}
}
$nestedURL = $parentURL != NULL ? $parentURL.'/'.$page->URLSegment : $page->URLSegment;
$output .= '
<li><a href="'.$nestedURL.'" title="Go to the '.Convert::raw2xml($page->Title).' page">'.Convert::raw2xml($page->MenuTitle).'</a>';
$whereStatement = "ParentID = ".$page->ID." AND ClassName NOT IN(".self::$siteMapSkipPageTypes.")";
$childPages = DataObject::get("Page", $whereStatement);
if($childPages) {
$output .= $this->makeChildList($childPages, $nestedURL);
}
$output .= '</li>';
}
$output .= '
</ul>
';
}
return $output;
}
There is probably a better way with 2.4, but this works well for the meantime.