A middleware is an old and powerful concept that we have in software development, it is really useful when we have routing related patterns in our applications.
If you’re not sure about the meaning of middleware, there is a Simple Explanation of Express Middleware that can help you to learn more about how them work (at least in Express and Node, but the concept is the same).
But, is this only for backend? No, actually is very common in both (frontend or backend) when you have routing in your application, and we are using this concept since Single Page Applications appeared in our lives.
And… do my SPA website need this?
There are some examples that can explain when you can use a middleware:
- Don’t allow users that didn’t logged into your website to visit a page.
- Allow only certain types of users to see a page (Roles: Administrator, Editor, etc.)
- Reset settings or clean storage.
- Only allow to access to a page logged users older than a certain age.
And some others…
I really need this! How can I use with Vue?
Thanks to Vue Router this is going to be super easy! Because this plugin has implemented a similar concept called ‘Navigation Guards’.