404 Error when routing custom pages
Hello everyone,
We have a member panel where we had to build many custom pages. For example, categories, category, posts, post and tags.
The categories have the following route:
/categories
- This works without any problems.
The category has the following route: /categories/{category:slug}
- This immediately returns a 404, but it is listed under php artisan route:list
.
The posts have the following route: /posts
- This also works without any problems.
The post has the following route: {category}/{post:slug}
- This also works without any problems.
The tags have the following route: tags/{tag:slug}
- This immediately returns a 404, but it is listed under php artisan route:list
.
What is the quickest way to fix this?
PS: Does it make a difference if I create the custom pages as Livewire components with extends Filament\Pages\Page
or if I use a custom page directly?Solution:Jump to solution
I solved it. The reason why it didn't work properly is the order in which you specify the pages in the provider.
9 Replies
PS: Does it make a difference if I create the custom pages as Livewire components with extends Filament\Pages\Page or if I use a custom page directly?Should be the same. Can you share the full output of
artisan route:list
for the Filament pages?Did you check for differences in those models?
Did you set the key for the models? Did you modify the navigation items method or similar?
Earlier, I replaced
categories/{category:slug}
with just {category:slug}
, and then it worked again.It doesn't look like that, but do the routes clash somewhere? So it's using the wrong route, because it matches the placeholder?
It shouldn't, I've tried various things and it has never worked properly.
Please also take a look at the route names. I believe there is also a bug/error in Filament.
My wish would be as follows:
Post:
/{category:slug}/{post:slug}
Posts: /posts
or via the category: /{category:slug}
Categories: /categories
Tags: /tags/{tag:slug}
Direct routing is still handled by Laravel, otherwise I would have thought that it might be related to Filament messing things up because it builds the routes in a strange way.
Okay. Weird. I've now got everything working except for tags/{tag:slug}
.
no idea?I am going to guess tag:slug page is being hit but not finding a tag so returning a 404, view the action/stack trace of it returning a 404
Solution
I solved it. The reason why it didn't work properly is the order in which you specify the pages in the provider.
That’s what I meant with „clashing routes“ 😅