How to do Nextjs dynamic routing? - dynamic

How to do Nextjs dynamic routing?
I've code like this already, this works, however if you refresh the page, you will get 404 page
<Link
href={`/categorypage?c1=${data.categoria}&c2=${data2.categoria}`}
as={`${data.categoria}/${data2.categoria}`}>
<a>{data2.categorianame}</a>
</Link>

Related

VueJS real SEO friendly 404 page for search engines like Google / MSN

I am not VueJS programmer, but I work with in a company where we developing a VueJS website.
The website have articles. The URL is something like this:
http://example.com/here_is_news_from_sofia.htm
However if you type:
http://example.com/here_is_news_from_blabla.htm
You should go to 404 page.
I inspected several websites and stackoverflow questions, they explain how you should do catch-all router etc, so finally you get a page with "404 Not Found" text on it.
However, in ALL cases, the HTTP code send to the client is not 404, but 200.
With my team, I elaborated this:
When you go to any article, you get something like this:
<html>
<body>
<div id="app">
<app />
</div>
<script src="/js/client.js"></script>
</body>
</html>
Of course, if you click on a link, this page remains and everything is loaded via JS dynamically.
Then lets suppose article is not found.
VueJS will be able to show "404 Not Found" as text, but because HTTP headers are already send (HTML page is already loaded), it will not be able to send 404 code to the client.
For the same reason, VueJS can not send 301 code redirect to the client.
VueJS can incorrectly change the URL in the browser to "http://example.com/404.htm" - this is NOT a correct solution for search engines, since this is purely client-side (in-browser) "trick".
The other think it can do is to execute fancy redirect, as shown here Vue-router redirect on page not found (404) :
Vue.component("page-not-found", {
template: "",
created: function() {
// Redirect outside the app using plain old javascript
window.location.href = "/404.htm";
}
}
This will make the browser to reload the /404.htm page from the server and if the server (Apache / Nginx) is configured correctly, it will send "correct" 404 code to the client.
However I don't think Google and MSN will recognize that http://example.com/here_is_news_from_blabla.htm is a 404 page.
Am I missing anything?
Is there another way VueJS might handle this situation?
How VueJS websites gets indexed from search engines like Google and MSN?
Off topic bonus question - can VueJS generate visible HTML code that contains the article?
If that's a single page application, you can set up dynamic route matching with parameters with vue-router. And dynamically update your meta tags with javascript. I am using quasar vue framework, which handles all of this SEO feature.
I added slug data to the article saved in the database and use it as a route parameter.
https://quasar.dev/vue-composables/use-meta
https://router.vuejs.org/guide/essentials/dynamic-matching.html
You can use quasar vue framework, develop vue app in SSR mode and deploy it to the server.
https://quasar.dev/quasar-cli-vite/developing-ssr/handling-404-and-500-errors

Blazor: Implementing 404 not found page

I'd like to implement a page internal to my application that appears when the blazor router is unable to find a matching route. Currently, all requests are routing to index.html so I'm unable to handle errors through iis as I may normally. If I enter an invalid route, I will be shown a blank page (which is actually index.html) and receive a console error:
'Router' cannot find any component with a route for '/some/Nonexistent/Route'.
It seems like I should be able to handle this since the blazor router is able to recognize that there is no route defined which matches the requested route however I've so far been unable to find any documentation on this.
How can I implement this? Is there a way to hook into the blazor router and direct all non found routes to a predefined error route?
I see https://github.com/aspnet/AspNetCore/issues/5489 has an issue listed for a 404 handler however I'm not sure if that is for something more robust and production ready than what I'm looking to do
In App.razor, add the <NotFound> element under <Router> and set what content you'd like to be displayed when Blazor can't find the specified route.
For example:
<Router AppAssembly="#typeof(Program).Assembly">
<NotFound>
<h1>404 Not Found</h1>
</NotFound>
</Router>
(Note: If it's a server side app, then it would be #typeof(Startup).Assembly)
Source
Try this:
App.cshtml
<Router AppAssembly=typeof(Program).Assembly FallbackComponent="typeof(Error404)" >
Create a Component named Error404.cshtml
Note: This is only a guess I gathered from digging the Router class. See https://github.com/aspnet/AspNetCore/blob/343208331d9ebbb3a67880133f4139bee2cb1c71/src/Components/src/Microsoft.AspNetCore.Components/Routing/Router.cs
Please, let me know if it works for you.
For SEO enough add in App.razor:
<NotFound>
<h1>404 Not Found</h1>
<HeadContent>
<meta name="robots" content="noindex" />
</HeadContent>
</NotFound>
and implement Sitemap.xml
You can use this link for .net 5.0 blazor server-side application.
You can handle 404 and status code correct
https://stackoverflow.com/a/69404900/2123797

How to implement Canonical Tag in Pimcore CMS?

I have to implement canonical tags on a customer website which works with Pimcore CMS. Does somebody has experience with that or can give me some hints?
A way could be to set a Document Property and render it in your view.
see: https://pimcore.com/docs/4.6.x/Development_Documentation/Tools_and_Features/Properties.html
For PHP Templating Engine you could add this line and set it properly in your Backend.
<link rel="canonical" href="<?= $this->document->getProperty('canonicalHref');?>" />
If you want to set this tag globally, or with some simple url regex matching, you can do it straight from the admin panel using Marketing > Tag & Snippet Management.
To allow a user to customize URL you can create the predefined property 'canonicalHref',
then put in layout twig file:
<head>
....
{% set canonicalUrl = document.getProperty('canonicalHref')|default(app.request.getUri??'') %}
<link rel="canonical" href="{{ canonicalUrl }}"/>
</head>
You will still need:
to customize HTTP headers in PDF files generated for the print version
and to add 301 redirects from HTTP to HTTPS version.

Not sure how to fix unsecured content over SSL

My website is here, and visiting it in Chrome gives the 'load unsafe script' error and unsecured content errors in the console. Firefox loads the site, but there isn't a lock.
My site is entirely in PHP, and I'm not sure where to start. The console and firebug said that the site was loading unsecure scripts over HTTP, but how do I make it all HTTPS?
Thanks in advance!
Your HTML has lots of links to http:// resources, eg.:
<link rel="stylesheet" type="text/css" href="http://portal.thespartaninstitute.com/...">
You need to ditch the http: part and just link to //portal.thespartaninstitute.com/... - that will then use https when the page has been loaded that way.

Why are my CSS/JS resources loading with HTTPS?

All my page resources - css/js/images- are failing to load. I'm using relative links (e.g. <link href="includes/css/athletics.css" rel="stylesheet" type="text/css" />), and when I inspect the network tab in firebug it shows that all the resource GET requests are HTTPS, even though the main page request is an HTTP request. What would be causing this?
I'm running on a WAMPServer with some alias directories set up.
do you have a <base ... > defined?