fix: Replace hardcoded paths with route/url helpers for subdirectory support

Files updated:
- layouts/knowledge-base.blade.php - Use url('/') for home link
- layouts/navigation.blade.php - Use url('/') for nav links
- layouts/guest.blade.php - Use url('/') for logo link
- Document.php - Use route() for wiki links
- DocumentLink.php - Use route() for URL attribute
- AuthenticatedSessionController.php - Use url('/') for redirects
- DocumentEditor.php - Use url('/') for redirect
- ProfileController.php - Use url('/') for redirect

This ensures the app works when deployed in a subdirectory
This commit is contained in:
2025-11-29 17:14:46 +09:00
parent 25613eea05
commit 893d3c7a69
9 changed files with 18 additions and 12 deletions

6
package-lock.json generated Normal file
View File

@@ -0,0 +1,6 @@
{
"name": "knowledge-base",
"lockfileVersion": 3,
"requires": true,
"packages": {}
}

View File

@@ -33,7 +33,7 @@ public function store(LoginRequest $request): RedirectResponse
return redirect()->intended(route('dashboard', absolute: false)); return redirect()->intended(route('dashboard', absolute: false));
} }
return redirect()->intended('/'); return redirect()->intended(url('/'));
} }
/** /**
@@ -47,6 +47,6 @@ public function destroy(Request $request): RedirectResponse
$request->session()->regenerateToken(); $request->session()->regenerateToken();
return redirect('/'); return redirect(url('/'));
} }
} }

View File

@@ -55,6 +55,6 @@ public function destroy(Request $request): RedirectResponse
$request->session()->invalidate(); $request->session()->invalidate();
$request->session()->regenerateToken(); $request->session()->regenerateToken();
return Redirect::to('/'); return Redirect::to(url('/'));
} }
} }

View File

@@ -80,7 +80,7 @@ public function delete(DocumentService $documentService)
if ($homeDocument) { if ($homeDocument) {
return redirect()->route('documents.show', $homeDocument); return redirect()->route('documents.show', $homeDocument);
} }
return redirect('/'); return redirect(url('/'));
} catch (\Exception $e) { } catch (\Exception $e) {
session()->flash('error', 'Error deleting document: ' . $e->getMessage()); session()->flash('error', 'Error deleting document: ' . $e->getMessage());
} }

View File

@@ -154,9 +154,9 @@ function ($matches) {
->first(); ->first();
if ($targetDocument) { if ($targetDocument) {
return '<a href="/documents/' . $targetDocument->slug . '" class="wiki-link">' . e($linkTitle) . '</a>'; return '<a href="' . route('documents.show', $targetDocument->slug) . '" class="wiki-link">' . e($linkTitle) . '</a>';
} else { } else {
return '<a href="/documents/create?title=' . urlencode($linkTitle) . '" class="wiki-link wiki-link-new">' . e($linkTitle) . '</a>'; return '<a href="' . route('documents.create') . '?title=' . urlencode($linkTitle) . '" class="wiki-link wiki-link-new">' . e($linkTitle) . '</a>';
} }
}, },
$this->rendered_html $this->rendered_html

View File

@@ -57,9 +57,9 @@ public function isBroken(): bool
public function getUrlAttribute(): string public function getUrlAttribute(): string
{ {
if ($this->isBroken()) { if ($this->isBroken()) {
return '/documents/create?title=' . urlencode($this->target_title); return route('documents.create') . '?title=' . urlencode($this->target_title);
} }
return '/documents/' . $this->targetDocument->slug; return route('documents.show', $this->targetDocument->slug);
} }
} }

View File

@@ -17,7 +17,7 @@
<body class="font-sans text-gray-900 antialiased"> <body class="font-sans text-gray-900 antialiased">
<div class="min-h-screen flex flex-col sm:justify-center items-center pt-6 sm:pt-0 bg-gray-100"> <div class="min-h-screen flex flex-col sm:justify-center items-center pt-6 sm:pt-0 bg-gray-100">
<div> <div>
<a href="/"> <a href="{{ url('/') }}">
<x-application-logo class="w-20 h-20 fill-current text-gray-500" /> <x-application-logo class="w-20 h-20 fill-current text-gray-500" />
</a> </a>
</div> </div>

View File

@@ -34,7 +34,7 @@
<div class="max-w-full mx-auto px-4 sm:px-6 lg:px-8"> <div class="max-w-full mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between h-16"> <div class="flex justify-between h-16">
<div class="flex items-center space-x-3"> <div class="flex items-center space-x-3">
<a href="/" class="flex items-center space-x-3"> <a href="{{ url('/') }}" class="flex items-center space-x-3">
<x-application-logo class="block h-8 w-auto fill-current text-gray-800" /> <x-application-logo class="block h-8 w-auto fill-current text-gray-800" />
<h1 class="text-xl font-semibold text-gray-900"> <h1 class="text-xl font-semibold text-gray-900">
{{ config('app.name', 'Knowledge Base') }} {{ config('app.name', 'Knowledge Base') }}

View File

@@ -15,7 +15,7 @@
<x-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')"> <x-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
{{ __('messages.nav.dashboard') }} {{ __('messages.nav.dashboard') }}
</x-nav-link> </x-nav-link>
<x-nav-link href="/" :active="false"> <x-nav-link :href="url('/')" :active="false">
<svg class="w-4 h-4 mr-1 inline" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg class="w-4 h-4 mr-1 inline" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6.042A8.967 8.967 0 006 3.75c-1.052 0-2.062.18-3 .512v14.25A8.987 8.987 0 016 18c2.305 0 4.408.867 6 2.292m0-14.25a8.966 8.966 0 016-2.292c1.052 0 2.062.18 3 .512v14.25A8.987 8.987 0 0018 18a8.967 8.967 0 00-6 2.292m0-14.25v14.25"></path> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6.042A8.967 8.967 0 006 3.75c-1.052 0-2.062.18-3 .512v14.25A8.987 8.987 0 016 18c2.305 0 4.408.867 6 2.292m0-14.25a8.966 8.966 0 016-2.292c1.052 0 2.062.18 3 .512v14.25A8.987 8.987 0 0018 18a8.967 8.967 0 00-6 2.292m0-14.25v14.25"></path>
</svg> </svg>
@@ -82,7 +82,7 @@
<x-responsive-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')"> <x-responsive-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
{{ __('messages.nav.dashboard') }} {{ __('messages.nav.dashboard') }}
</x-responsive-nav-link> </x-responsive-nav-link>
<x-responsive-nav-link href="/" :active="false"> <x-responsive-nav-link :href="url('/')" :active="false">
{{ __('messages.nav.knowledge_base') }} {{ __('messages.nav.knowledge_base') }}
</x-responsive-nav-link> </x-responsive-nav-link>
</div> </div>