Commit d8891e44 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix navbar/footer anchor links not working on subpages

Anchor-only hrefs (#section-*) do nothing on non-homepage routes.
Compute $navBase prefix (full homepage URL on subpages, empty on homepage)
and prepend it to all section links in all 5 navbar variants, mobile menu,
and footer blocks partial.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 047d2619
@php @php
$navBase = $navBase ?? (request()->routeIs('website.show') ? '' : route('website.show', ['slug' => $academy->slug]));
$blocks = $settings->footer_blocks ?? []; $blocks = $settings->footer_blocks ?? [];
$columns = $settings->footer_columns ?? 4; $columns = $settings->footer_columns ?? 4;
$gridClass = match($columns) { $gridClass = match($columns) {
...@@ -42,7 +43,7 @@ ...@@ -42,7 +43,7 @@
@else @else
@foreach($sections->take(6) as $navSection) @foreach($sections->take(6) as $navSection)
<li> <li>
<a href="#section-{{ $navSection->section_key->value }}" class="{{ $mutedColor }} hover:text-[var(--site-accent)] transition-colors text-sm"> <a href="{{ $navBase ?? '' }}#section-{{ $navSection->section_key->value }}" class="{{ $mutedColor }} hover:text-[var(--site-accent)] transition-colors text-sm">
{{ $navSection->title ?? $navSection->section_key->label() }} {{ $navSection->title ?? $navSection->section_key->label() }}
</a> </a>
</li> </li>
...@@ -144,7 +145,7 @@ class="w-10 h-10 rounded-lg bg-white/5 border {{ $borderColor }} flex items-cent ...@@ -144,7 +145,7 @@ class="w-10 h-10 rounded-lg bg-white/5 border {{ $borderColor }} flex items-cent
<ul class="space-y-2"> <ul class="space-y-2">
@foreach($sections->take(6) as $navSection) @foreach($sections->take(6) as $navSection)
<li> <li>
<a href="#section-{{ $navSection->section_key->value }}" class="{{ $mutedColor }} hover:text-[var(--site-accent)] transition-colors text-sm"> <a href="{{ $navBase ?? '' }}#section-{{ $navSection->section_key->value }}" class="{{ $mutedColor }} hover:text-[var(--site-accent)] transition-colors text-sm">
{{ $navSection->title ?? $navSection->section_key->label() }} {{ $navSection->title ?? $navSection->section_key->label() }}
</a> </a>
</li> </li>
......
{{-- Shared mobile menu, included by all navbar variants --}} {{-- Shared mobile menu, included by all navbar variants --}}
@php $navBase = $navBase ?? (request()->routeIs('website.show') ? '' : route('website.show', ['slug' => $academy->slug])); @endphp
<div id="mobile-menu" class="hidden lg:hidden bg-black/95 backdrop-blur-lg border-t border-white/10"> <div id="mobile-menu" class="hidden lg:hidden bg-black/95 backdrop-blur-lg border-t border-white/10">
<div class="px-4 py-4 space-y-1"> <div class="px-4 py-4 space-y-1">
@foreach($sections as $section) @foreach($sections as $section)
<a href="#section-{{ $section->section_key->value }}" <a href="{{ $navBase }}#section-{{ $section->section_key->value }}"
class="block px-4 py-3 text-white/80 hover:text-white hover:bg-white/5 rounded-lg transition-colors" class="block px-4 py-3 text-white/80 hover:text-white hover:bg-white/5 rounded-lg transition-colors"
onclick="document.getElementById('mobile-menu').classList.add('hidden')"> onclick="document.getElementById('mobile-menu').classList.add('hidden')">
{{ $section->title ?? $section->section_key->label() }} {{ $section->title ?? $section->section_key->label() }}
......
@php $navBase = request()->routeIs('website.show') ? '' : route('website.show', ['slug' => $academy->slug]); @endphp
<nav class="site-nav site-nav--solid" id="site-navbar"> <nav class="site-nav site-nav--solid" id="site-navbar">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex items-center justify-between h-20"> <div class="flex items-center justify-between h-20">
{{-- Links Start --}} {{-- Links Start --}}
<div class="hidden lg:flex items-center gap-1 flex-1 justify-end"> <div class="hidden lg:flex items-center gap-1 flex-1 justify-end">
@foreach($sections->take(3) as $navSection) @foreach($sections->take(3) as $navSection)
<a href="#section-{{ $navSection->section_key->value }}" class="px-3 py-2 text-sm font-medium text-white/80 hover:text-white rounded-lg hover:bg-white/5 transition-all"> <a href="{{ $navBase }}#section-{{ $navSection->section_key->value }}" class="px-3 py-2 text-sm font-medium text-white/80 hover:text-white rounded-lg hover:bg-white/5 transition-all">
{{ $navSection->title ?? $navSection->section_key->label() }} {{ $navSection->title ?? $navSection->section_key->label() }}
</a> </a>
@endforeach @endforeach
</div> </div>
{{-- Centered Logo --}} {{-- Centered Logo --}}
<a href="#section-hero" class="flex items-center gap-3 group mx-8"> <a href="{{ $navBase }}#section-hero" class="flex items-center gap-3 group mx-8">
@if($academy->logo_path) @if($academy->logo_path)
<img src="{{ asset('storage/' . $academy->logo_path) }}" alt="{{ $academy->name_ar }}" class="h-12 w-12 rounded-xl object-contain transition-transform group-hover:scale-110"> <img src="{{ asset('storage/' . $academy->logo_path) }}" alt="{{ $academy->name_ar }}" class="h-12 w-12 rounded-xl object-contain transition-transform group-hover:scale-110">
@endif @endif
...@@ -21,11 +22,11 @@ ...@@ -21,11 +22,11 @@
{{-- Links End --}} {{-- Links End --}}
<div class="hidden lg:flex items-center gap-1 flex-1"> <div class="hidden lg:flex items-center gap-1 flex-1">
@foreach($sections->skip(3)->take(3) as $navSection) @foreach($sections->skip(3)->take(3) as $navSection)
<a href="#section-{{ $navSection->section_key->value }}" class="px-3 py-2 text-sm font-medium text-white/80 hover:text-white rounded-lg hover:bg-white/5 transition-all"> <a href="{{ $navBase }}#section-{{ $navSection->section_key->value }}" class="px-3 py-2 text-sm font-medium text-white/80 hover:text-white rounded-lg hover:bg-white/5 transition-all">
{{ $navSection->title ?? $navSection->section_key->label() }} {{ $navSection->title ?? $navSection->section_key->label() }}
</a> </a>
@endforeach @endforeach
<a href="{{ $settings->navbar_cta_link ?? '#section-contact' }}" class="ms-2 site-btn site-btn--primary text-sm !py-1.5 !px-4"> <a href="{{ $settings->navbar_cta_link ?? ($navBase . '#section-contact') }}" class="ms-2 site-btn site-btn--primary text-sm !py-1.5 !px-4">
{{ $settings->navbar_cta_text ?? 'سجّل الآن' }} {{ $settings->navbar_cta_text ?? 'سجّل الآن' }}
</a> </a>
</div> </div>
......
@php $navBase = request()->routeIs('website.show') ? '' : route('website.show', ['slug' => $academy->slug]); @endphp
<nav class="site-nav site-nav--floating" id="site-navbar"> <nav class="site-nav site-nav--floating" id="site-navbar">
<div class="max-w-7xl mx-auto px-4 sm:px-6"> <div class="max-w-7xl mx-auto px-4 sm:px-6">
<div class="flex items-center justify-between h-16"> <div class="flex items-center justify-between h-16">
<a href="#section-hero" class="flex items-center gap-3 group"> <a href="{{ $navBase }}#section-hero" class="flex items-center gap-3 group">
@if($academy->logo_path) @if($academy->logo_path)
<img src="{{ asset('storage/' . $academy->logo_path) }}" alt="{{ $academy->name_ar }}" class="h-9 w-9 rounded-lg object-contain transition-transform group-hover:scale-110"> <img src="{{ asset('storage/' . $academy->logo_path) }}" alt="{{ $academy->name_ar }}" class="h-9 w-9 rounded-lg object-contain transition-transform group-hover:scale-110">
@endif @endif
...@@ -10,14 +11,14 @@ ...@@ -10,14 +11,14 @@
<div class="hidden lg:flex items-center gap-1"> <div class="hidden lg:flex items-center gap-1">
@foreach($sections->take(6) as $navSection) @foreach($sections->take(6) as $navSection)
<a href="#section-{{ $navSection->section_key->value }}" class="px-3 py-1.5 text-sm font-medium text-white/80 hover:text-white rounded-lg hover:bg-white/10 transition-all"> <a href="{{ $navBase }}#section-{{ $navSection->section_key->value }}" class="px-3 py-1.5 text-sm font-medium text-white/80 hover:text-white rounded-lg hover:bg-white/10 transition-all">
{{ $navSection->title ?? $navSection->section_key->label() }} {{ $navSection->title ?? $navSection->section_key->label() }}
</a> </a>
@endforeach @endforeach
</div> </div>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<a href="{{ $settings->navbar_cta_link ?? '#section-contact' }}" class="hidden sm:inline-flex site-btn site-btn--primary text-sm !py-1.5 !px-4 !rounded-full"> <a href="{{ $settings->navbar_cta_link ?? ($navBase . '#section-contact') }}" class="hidden sm:inline-flex site-btn site-btn--primary text-sm !py-1.5 !px-4 !rounded-full">
{{ $settings->navbar_cta_text ?? 'سجّل الآن' }} {{ $settings->navbar_cta_text ?? 'سجّل الآن' }}
</a> </a>
<button type="button" class="lg:hidden p-2 rounded-lg text-white/80 hover:text-white hover:bg-white/10 transition-colors" onclick="document.getElementById('mobile-menu').classList.toggle('hidden')" aria-label="القائمة"> <button type="button" class="lg:hidden p-2 rounded-lg text-white/80 hover:text-white hover:bg-white/10 transition-colors" onclick="document.getElementById('mobile-menu').classList.toggle('hidden')" aria-label="القائمة">
......
@php $navBase = request()->routeIs('website.show') ? '' : route('website.show', ['slug' => $academy->slug]); @endphp
<nav class="site-nav site-nav--transparent" id="site-navbar"> <nav class="site-nav site-nav--transparent" id="site-navbar">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex items-center justify-between h-20"> <div class="flex items-center justify-between h-20">
<a href="#section-hero" class="flex items-center gap-3 group"> <a href="{{ $navBase }}#section-hero" class="flex items-center gap-3 group">
@if($academy->logo_path) @if($academy->logo_path)
<img src="{{ asset('storage/' . $academy->logo_path) }}" alt="{{ $academy->name_ar }}" class="h-10 w-10 rounded-lg object-contain transition-transform group-hover:scale-110"> <img src="{{ asset('storage/' . $academy->logo_path) }}" alt="{{ $academy->name_ar }}" class="h-10 w-10 rounded-lg object-contain transition-transform group-hover:scale-110">
@endif @endif
...@@ -14,7 +15,7 @@ ...@@ -14,7 +15,7 @@
{{ __('لوحة التحكم') }} {{ __('لوحة التحكم') }}
</a> </a>
@endauth @endauth
<a href="{{ $settings->navbar_cta_link ?? '#section-contact' }}" class="site-btn site-btn--primary text-sm !py-2 !px-5"> <a href="{{ $settings->navbar_cta_link ?? ($navBase . '#section-contact') }}" class="site-btn site-btn--primary text-sm !py-2 !px-5">
{{ $settings->navbar_cta_text ?? 'سجّل الآن' }} {{ $settings->navbar_cta_text ?? 'سجّل الآن' }}
</a> </a>
<button type="button" class="lg:hidden p-2 rounded-lg text-white/80 hover:text-white hover:bg-white/10 transition-colors" onclick="document.getElementById('mobile-menu').classList.toggle('hidden')" aria-label="القائمة"> <button type="button" class="lg:hidden p-2 rounded-lg text-white/80 hover:text-white hover:bg-white/10 transition-colors" onclick="document.getElementById('mobile-menu').classList.toggle('hidden')" aria-label="القائمة">
......
@php $navBase = request()->routeIs('website.show') ? '' : route('website.show', ['slug' => $academy->slug]); @endphp
<nav class="site-nav site-nav--solid" id="site-navbar"> <nav class="site-nav site-nav--solid" id="site-navbar">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex items-center justify-between h-20"> <div class="flex items-center justify-between h-20">
<a href="#section-hero" class="flex items-center gap-3 group"> <a href="{{ $navBase }}#section-hero" class="flex items-center gap-3 group">
@if($academy->logo_path) @if($academy->logo_path)
<img src="{{ asset('storage/' . $academy->logo_path) }}" alt="{{ $academy->name_ar }}" class="h-10 w-10 rounded-lg object-contain transition-transform group-hover:scale-110"> <img src="{{ asset('storage/' . $academy->logo_path) }}" alt="{{ $academy->name_ar }}" class="h-10 w-10 rounded-lg object-contain transition-transform group-hover:scale-110">
@endif @endif
...@@ -10,14 +11,14 @@ ...@@ -10,14 +11,14 @@
<div class="hidden lg:flex items-center gap-1"> <div class="hidden lg:flex items-center gap-1">
@foreach($sections->take(7) as $navSection) @foreach($sections->take(7) as $navSection)
<a href="#section-{{ $navSection->section_key->value }}" class="px-3 py-2 text-sm font-medium text-white/80 hover:text-white rounded-lg hover:bg-white/5 transition-all"> <a href="{{ $navBase }}#section-{{ $navSection->section_key->value }}" class="px-3 py-2 text-sm font-medium text-white/80 hover:text-white rounded-lg hover:bg-white/5 transition-all">
{{ $navSection->title ?? $navSection->section_key->label() }} {{ $navSection->title ?? $navSection->section_key->label() }}
</a> </a>
@endforeach @endforeach
</div> </div>
<div class="flex items-center gap-3"> <div class="flex items-center gap-3">
<a href="{{ $settings->navbar_cta_link ?? '#section-contact' }}" class="hidden sm:inline-flex site-btn site-btn--primary text-sm !py-2 !px-4"> <a href="{{ $settings->navbar_cta_link ?? ($navBase . '#section-contact') }}" class="hidden sm:inline-flex site-btn site-btn--primary text-sm !py-2 !px-4">
{{ $settings->navbar_cta_text ?? 'سجّل الآن' }} {{ $settings->navbar_cta_text ?? 'سجّل الآن' }}
</a> </a>
@auth @auth
......
@php $navBase = request()->routeIs('website.show') ? '' : route('website.show', ['slug' => $academy->slug]); @endphp
<nav class="site-nav site-nav--transparent" id="site-navbar"> <nav class="site-nav site-nav--transparent" id="site-navbar">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex items-center justify-between h-20"> <div class="flex items-center justify-between h-20">
<a href="#section-hero" class="flex items-center gap-3 group"> <a href="{{ $navBase }}#section-hero" class="flex items-center gap-3 group">
@if($academy->logo_path) @if($academy->logo_path)
<img src="{{ asset('storage/' . $academy->logo_path) }}" alt="{{ $academy->name_ar }}" class="h-10 w-10 rounded-lg object-contain transition-transform group-hover:scale-110"> <img src="{{ asset('storage/' . $academy->logo_path) }}" alt="{{ $academy->name_ar }}" class="h-10 w-10 rounded-lg object-contain transition-transform group-hover:scale-110">
@endif @endif
...@@ -10,14 +11,14 @@ ...@@ -10,14 +11,14 @@
<div class="hidden lg:flex items-center gap-1"> <div class="hidden lg:flex items-center gap-1">
@foreach($sections->take(7) as $navSection) @foreach($sections->take(7) as $navSection)
<a href="#section-{{ $navSection->section_key->value }}" class="px-3 py-2 text-sm font-medium text-white/80 hover:text-white rounded-lg hover:bg-white/5 transition-all"> <a href="{{ $navBase }}#section-{{ $navSection->section_key->value }}" class="px-3 py-2 text-sm font-medium text-white/80 hover:text-white rounded-lg hover:bg-white/5 transition-all">
{{ $navSection->title ?? $navSection->section_key->label() }} {{ $navSection->title ?? $navSection->section_key->label() }}
</a> </a>
@endforeach @endforeach
</div> </div>
<div class="flex items-center gap-3"> <div class="flex items-center gap-3">
<a href="{{ $settings->navbar_cta_link ?? '#section-contact' }}" class="hidden sm:inline-flex site-btn site-btn--primary text-sm !py-2 !px-4"> <a href="{{ $settings->navbar_cta_link ?? ($navBase . '#section-contact') }}" class="hidden sm:inline-flex site-btn site-btn--primary text-sm !py-2 !px-4">
{{ $settings->navbar_cta_text ?? 'سجّل الآن' }} {{ $settings->navbar_cta_text ?? 'سجّل الآن' }}
</a> </a>
@auth @auth
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment