Quick Start (MVC)
This quick start guide will walk you through the best practices for working with the Stratox Framework. We will show you how to create views, controllers, set up routes, and finally connect to a model, to get you started building a dynamic application using Stratox.
View
First, create a new JavaScript file for your view, for example: src/views/ShoppingList.js.
/**
* This is the main view
* It will also render the shopping list block component later
*/
export default function ShoppingList({ props }) {
return `
<article class="card-1 border-bottom">
<header class="content-header">
<h1 class="headline-1 mt-0">${props.title}</h1>
</header>
</article>
`;
}Now that the layout has been created, we just need to display it.
Controller
Next, we need to add a controller to manage the view. Create a new file named src/controllers/ShoppingListController.js.
Setting Up Routing
To specify where the page should be displayed, use the Stratox router. Open the file src/routes/app.js and modify it like below. I also slightly modified the start page example so that it does not take to much place.
Now, visit your development URL with the path /#list, for example: http://localhost:5173/#list. Your shopping list will be displayed.
Extending the View with a Component Block
Let's create a dynamic shopping list by modifying the layout and adding a component block called RenderShoppingList at the top of the view in src/views/ShoppingList.js. Also, make sure to render the block inside the main view so that it is displayed.
Now, visit your development URL with the path /#list (e.g., http://localhost:5173/#list), and you will see that a click event has been added to create a list. You will use the same bind function for every event (e.g., onclick, onchange, oninput) to automatically trigger changes. If needed, you can disable the automatic updates by passing false as the second argument to the bind function.
Model Example
Let us fetches some data from an API model to display additional information. Let's add a quick example to demonstrate how easy it is to fetch data and use it in our RenderShoppingList block component.
Open the file src/views/ShoppingList.js and add a ajax fetch request to a dummy API (se the 3 points in example below).
Now, visit your development URL with the path /#list and you will see the updated list that includes fetched data from the API.
Summary
This quick start guide showed you how to create a view, a controller, set up routing, and extend functionality using the Stratox Framework. You also learned how to add dynamic components and a modal example to extend the functionality of your views. Stratox provides a simple and user-friendly way to build powerful, dynamic applications with an organized MVC structure.
Feel free to experiment and expand upon these examples to build your application!
Continue to read more about components and features or jump to the Step by Step Tutorial.
Last updated