تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Adding a 404 Route0:00

Our pages are now loading correctly, but what about when a page is requested that doesn't exist? At the moment, we see nothing at all, when instead, I'd prefer to show a 404 page. Here's how. I'm going to go into my Routes section, and we'll register a new catch-all route. So we'll do * here for anything that is not matched specifically below, and that will load a custom component. Call it NotFound, anything you like. Okay, let's go ahead and create that, and then I'll create the file. All right, so we'll keep it simple here, like so.

Testing Missing Pages0:29

Okay, let's go ahead and create that, and then I'll create the file. All right, so we'll keep it simple here, like so. Okay, that should do it. So now, these pages will continue to load, but if I request anything that does not exist, we get our 404 page. But now, one quick thing before we finish up. Notice if I add an additional segment to the URI, as I did right here, we get Laravel's built-in 404. So it sounds like ViewRouter isn't taking effect in that case, and that's because of this.

Fixing Catch-All Regex1:02

So it sounds like ViewRouter isn't taking effect in that case, and that's because of this. If I go back to my General Routes section, here we're saying we'll find anything and load our app view. But that's only the first segment, it doesn't include anything else there. So let's tweak this route a bit. I'm going to say look for that where any is literally anything. So we'll use a regular expression here. A period represents any character, and a star represents zero or more of the preceding character. So we're genuinely saying look for any routes whatsoever.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟