Using Nuxt, we need to be able to render pseudo-routes, like this:
https://server.com/non-existent-route
Where "non-existent-route" is a dynamic path.
Normally, this would render error.vue. This is fine, as we've subverting the use of this page to render what we want. But... we just discovered that Nuxt is sending a 404 anyway! This only happens when the page is first loaded in a fresh tab, for some reason. This is very bad.
So, we need a way to avoid HTTP status 404 in some cases.
We found this:
https://medium.com/finn-no/hacking-nuxts-404-logic-for-maximum-awesome-and-easy-proxying-e4efaeb03d66
which is actually not as helpful as we had hoped it would be, as it simply provides a way to proxy another URL, sending us back to the same problem.
We suspect there might be some middleware solution to this problem... but have not been able to come up with it.
Turns out the answer was right here all long:
https://nuxtjs.org/guide/routing#dynamic-nested-routes
Rather disappointing that nobody suggested this extremely simple solution.
Related
I want to add a redirect functionality to an app in NextJS that fetches all content from a CMS (Contentful). In that process, I am thinking on two different approaches regarding the implementation in NextJS and content modelling.
I would like to better understand whether Approach I is doable and also a good practice, or if I should go for a different way, possibly approach II.
Approach I:
The actual situation I am trying to work with regarding content modelling:
Page
Url
Content
Redirects
From url
To url
Some Page content types will potentially have in the future some redirects, which means that for each redirect, a new Redirect content will be created.
I wrote a helper method that calls the CMS API and brings the content as a Redirects array, expecting that I could use that data to populate the redirects array returned inside the next.config.mjs file.
next.config.mjs fetchRedirects call screenshot(from inside redirects() )
In this approach I am finding some troubles, since I get the following error when running npm dev or trying to build:
node:internal/errors:490
ErrorCaptureStackTrace(err);
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/user/Dev/my-web/apps/api-calls/graphql/redirects' imported from /Users/user/Dev/DFDS/my-web/apps/dfds-unified-web/next.config.mjs
at new NodeError (node:internal/errors:399:5)
at finalizeResolution (node:internal/modules/esm/resolve:231:11)
at moduleResolve (node:internal/modules/esm/resolve:850:10)
at defaultResolve (node:internal/modules/esm/resolve:1058:11)
at nextResolve (node:internal/modules/esm/loader:164:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:419:18)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
at link (node:internal/modules/esm/module_job:76:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
Node.js v19.4.0
I can´t find proper documentation on this approach, and it is not clear to me why the app is crashing, since the import path to fetchRedirects is correctly referenced. I have tested the fetchRedirects method by calling it in the getStaticProps function inside the pages slug and it is working properly.
Hardcoding the redirects array inside next.config.mjs is not an option, since I would like to come up with a scalable solution to my problem.
Approach II
Page
Url
Redirect
Content
A second approach I am considering is having a Redirect content type inside the Page content type. By this means, I could return a redirect element from the getStaticProps function, together with the props for each of the pages, and then write some logic to redirect in case that the property is found.
I haven´t tried this last approach yet, but I understand that it is also possible, and I was also able to find some more references on how to do it. But I still would like to go for approach I if possible, since I would like to learn from it, or confirm that it is either inviable or not good practice.
I would highly appreciate any recomendation and possibly documentation that I am not finding at the moment.
Thank you for your time.
Have a nice day!
Is there any way to prevent URL showing when I am printing a webpage?
Actually all tag shows URL which is much annoying to some client. And my client asked me to avoid URL when printing a page. But I didn't found any solution yet. Tried couple of method already. No result.
Anyone can give me some suggestion is there any way to prevent URL actually?
First off, I saw similar posts already, but they weren't exactly what I am asking.
I used the Facebook Dev to create a like button for my website, stuck the code in and the the button showed up. The only issue is that it likes the wrong url when I click the button.
I'm pretty sure the issue is that I have it set to redirect automatically from mydomain.com to the most recent post. I think this is gumming up the works with the like button and causing it to like mydomain.com/mostrecentpost instead of simply liking mydomain.com.
Is there a way to correct this issue without having to get rid of the redirect (because that isn't an option)?
Sorry if that was a little wordy, wanted to make sure I explained the issue fully.
Is there a way to correct this issue without having to get rid of the redirect (because that isn't an option)?
Either don’t redirect in those cases where the user agent header of the request points to it being Facebook’s scraper;
or set the canonical URL of http://example.com/mostrecentpost to just http://example.com/ using the appropriate Open Graph meta tag. (Although that would mean you would not be able to like a single post any more, because all of your posts would just point to your base domain as the “real” website; so the first is probably the better option.)
May be I'm missing something, but the way now routedebbuger works (2+ version) is that it renders it's results on end of the page, which may be useful sometimes, but more often is annoying.
Would it be possible to return routedebbuger results only in case, when page is not found, when probability that our routing does not work as it supposed to work is the highest? In such case I would get information what is wrong right away, when I need it most (sure, this behavour would be enabled only in debug mode) .
If so, how to do that?
If you have a custom error controller and 404 view, you can use the version of Phil Haack's route debugger code that I put together to serve as a control on each page, which will be served even if you hit a 404.
I have an asp.net C# .net 3.5 page which contains several user controls. I am noticing that sometimes the html loaded on the browser is incomplete. It seems to get cut-off.
Any suggestions on how to troubleshoot whats the root cause?
This can be symptomatic of server errors or proxy problems. I would use Fiddler to check what's going back and forth between your browser and the server. If you are getting any 500 (server error) response codes, that would be a good place to look.
Another thing to check would be javascript errors on the page, because depending on what your javascripts are doing, errors can prevent loading of other content in some cases.
womp probably has most of the bases covered, but the other angle that can lead to issues like this would be exceptions getting eaten but causing processing to stop, thereby sending half the page or somesuch.
Verify that your HTML is being written to the page by viewing the source code of the page after it loads. My guess is that the HTML that is being output is invalid, and that the browser isn't able to properly display it. Make sure all your HTML tags are properly closed and balanced.
It could also be an issue with the request being ended midway through. Try removing one control at a time from the page and see if the situation improves. If it does, you'll know which control is to blame.
It is quite unlikely that it is the same problem, but I had that happen before where the page had a custom filter attached to response.filter which reformatted the output to fix up some dotnet SEO problems. And the one we wrote had a bug where one regular expression consumed a bit too much copy in some instances and broke the output