Checking for current route always returns false
See original GitHub issueDescription
I currently have three routes but when checking if I am on the current route always returns false
.
Expected behavior
When I am on the route the route().current('route_name')
should return true
.
Environment
- Laravel version: 8.12
- Ziggy version: 0.9.4
- Jetstream version: 1.6
Related routes:
Route::get('/', function () {
return view('welcome');
});
Route::middleware(['auth:sanctum', 'verified'])->get('/courses', function () {
return Inertia\Inertia::render('Courses');
})->name('courses');
Route::middleware(['auth:sanctum', 'verified'])->get('/course/{id}', function (int $id) {
return Inertia\Inertia::render('Course');
})->name('course');
Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
return Inertia\Inertia::render('Dashboard');
})->name('dashboard');
Ziggy.routes
:
undefined
When I check for Ziggy.namedRoutes I get this:
{
"ignition.healthCheck": {
"uri": "_ignition/health-check",
"methods": [
"GET",
"HEAD"
],
"domain": null
},
"ignition.executeSolution": {
"uri": "_ignition/execute-solution",
"methods": [
"POST"
],
"domain": null
},
"ignition.shareReport": {
"uri": "_ignition/share-report",
"methods": [
"POST"
],
"domain": null
},
"ignition.scripts": {
"uri": "_ignition/scripts/{script}",
"methods": [
"GET",
"HEAD"
],
"domain": null
},
"ignition.styles": {
"uri": "_ignition/styles/{style}",
"methods": [
"GET",
"HEAD"
],
"domain": null
},
"login": {
"uri": "login",
"methods": [
"GET",
"HEAD"
],
"domain": null
},
"logout": {
"uri": "logout",
"methods": [
"POST"
],
"domain": null
},
"password.request": {
"uri": "forgot-password",
"methods": [
"GET",
"HEAD"
],
"domain": null
},
"password.reset": {
"uri": "reset-password/{token}",
"methods": [
"GET",
"HEAD"
],
"domain": null
},
"password.email": {
"uri": "forgot-password",
"methods": [
"POST"
],
"domain": null
},
"password.update": {
"uri": "reset-password",
"methods": [
"POST"
],
"domain": null
},
"register": {
"uri": "register",
"methods": [
"GET",
"HEAD"
],
"domain": null
},
"user-profile-information.update": {
"uri": "user/profile-information",
"methods": [
"PUT"
],
"domain": null
},
"user-password.update": {
"uri": "user/password",
"methods": [
"PUT"
],
"domain": null
},
"password.confirm": {
"uri": "user/confirm-password",
"methods": [
"GET",
"HEAD"
],
"domain": null
},
"password.confirmation": {
"uri": "user/confirmed-password-status",
"methods": [
"GET",
"HEAD"
],
"domain": null
},
"two-factor.login": {
"uri": "two-factor-challenge",
"methods": [
"GET",
"HEAD"
],
"domain": null
},
"profile.show": {
"uri": "user/profile",
"methods": [
"GET",
"HEAD"
],
"domain": null
},
"other-browser-sessions.destroy": {
"uri": "user/other-browser-sessions",
"methods": [
"DELETE"
],
"domain": null
},
"current-user.destroy": {
"uri": "user",
"methods": [
"DELETE"
],
"domain": null
},
"current-user-photo.destroy": {
"uri": "user/profile-photo",
"methods": [
"DELETE"
],
"domain": null
},
"courses": {
"uri": "courses",
"methods": [
"GET",
"HEAD"
],
"domain": null
},
"course": {
"uri": "course/{id}",
"methods": [
"GET",
"HEAD"
],
"domain": null
},
"dashboard": {
"uri": "dashboard",
"methods": [
"GET",
"HEAD"
],
"domain": null
}
}
Ziggy call and context:
I am using the default configuration of Laravel Jetstream, the problem occurs in AppLayout.vue
<jet-nav-link :href="route('dashboard')" :active="route().current('dashboard')">
Dashboard
</jet-nav-link>
<jet-nav-link :href="route('courses')" :active="route().current('courses')">
Cursussen
</jet-nav-link>
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
Angular Router route guard CanActivate always returns false
I have used CanActivate to protect a page but it always returning false because of that I can not access ...
Read more >Can't do isActive check · Issue #3266 · remix-run/react-router
It seems to me that isActive checks if a path is active not if a route is active. Meaning if you are on...
Read more >Routing in ASP.NET Core - Microsoft Learn
Routing is responsible for matching incoming HTTP requests and dispatching those requests to the app's executable endpoints.
Read more >Router - Angular
Configures how the Router attempts to restore state when a navigation is cancelled. 'replace' - Always uses location.
Read more >file_exists - Manual - PHP
This function will return false for symlinks pointing to non-existing ... file_exists() returns always false when trying to check a remote file via...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi, @basvandinther I made a simple workaround for this (for my convenience 😅 - using Vue.js and Inertia.js), and I don’t know if it will help you.
This works well for me (I know it could be neater 😅)
Okay, gonna try this tomorrow. Thank you very much for your quick help.