Using the following setup
have a page called user that dynamically loads page content from a URL parameter.
The route for the page is /:username
so https://website.com/example would pull up the database record for the username example and fill in some dynamic data on the page.
What is the best way to handle it when there is no database record matching the username?
Had two ideas but not sure which way is best or if there are any problems with either.
First idea was to just use a condition when it loads the user content and redirect to a 404 or error page directly in the server action if there is no matching record.
Second was to add an error message to the page itself saying that no user with that name exists. Would also have to hide all the content on the page that would normally be filled in dynamically.
Also wasn’t sure if I could do anything by have the route itself run the server action and then only load the page if a record is found?
My main concern is SEO, I don’t want a bunch of pages indexed for usernames that don’t exist and have no content, but I’m not sure how Wappler dynamic routes work with Google crawlers. Would Google only find the page if it were linked elsewhere on the site or in a sitemap?
Creating a server action that fetches the SEO (sounds like you want dynamic SEO) and also in this action a single query that uses the PARAM variable defined in the URL.
Then a condition on wether a record is returned or not. If the query has a record do nothing and if it doesn’t have a redirect step that goes to a 404
Place this action as the server side data for the content page
Then another server action to load the actual page data and a server connect on the page.
Thanks for the idea, it definitely makes more sense to do it in the server side. Thanks for the link as well, I must have missed it when looking into this.
Google will try to index pages that you linked to in the content of your site or in the sitemap. Google can’t just try to guess an url that does not exist and is not linked anywhere