Aurelia's numerous applications spread across various pages

Currently, I am in the process of finalizing the initial release of a large-scale website built using PHP (Phalcon), MySQL, and JQuery. The technology stack may be a bit outdated, but it was originally prototyped years ago and due to various circumstances, it has taken quite some time to reach the production stage.

Although hard page reloads are not the latest trend, they do have their place in a complex application like this, especially when transitioning to different sections serving unique purposes. The website currently mimics a single page app with hashed URLs and ajax content loading, particularly where SEO is not a concern. However, the reliance on JQuery for these functionalities has resulted in a messy and challenging codebase. Additionally, features like notifications in the navigation bar are updated via ajax on every page.

While PHP is my area of expertise, I lack proficiency in JavaScript. It has become apparent that JQuery alone is insufficient for the website's needs. I am in need of a JavaScript framework that can manage templating, local routing, http requests, and follow an MV..? structure for better organization and maintainability. After exploring options like Angular 1 and Angular 2, I came across Aurelia alpha, which seemed promising with its modern syntax and design. With more resources and documentation available for Aurelia 1 beta, I am inclined to adopt it for this project.

Despite my understanding of Aurelia's capabilities, I am struggling with integrating it into the current project setup.

Integration

  1. Each section of the site will require distinct Aurelia apps.
  2. Multiple Aurelia apps may be necessary per page.
  3. Some Aurelia apps will be utilized across all pages.

I came across an article by Patrick Walters detailing how to incorporate Aurelia apps on different parts of the site by specifying the app name when calling it on the element;

<body aurelia-app="main" start="app">

Following this, setting up a shared main.js file like;

aurelia.start().then(a => {
  let start = a.host.attributes.start.value;
  a.setRoot(start);
});

While this approach seemed logical, I encountered issues when placing the call in a div instead of the body, resulting in an unresolved 'host' error. It seems that 'host' should be replaced with the element itself, but the exact method eludes me.

Any insights on integrating Aurelia in this manner would be greatly appreciated.

While I have come across similar solutions on SO, many of them involve duplicating 'main.js' instead of reusing it, which does not seem ideal.

Structure

In an attempt to create a more organized directory structure, I experimented with moving source files to subdirectories. However, the only way I could make this work was by adding a named path to each in the configuration, such as

"welcome*": "dist/welcome/welcome*",
. Is this the optimal or sole approach for achieving this?

Answer №1

It's difficult to determine the perfect answer to your question as it ultimately depends on your specific situation. Only you can decide which strategy will work best for you. From what I can gather, it seems like Aurelia could be a suitable option for implementing your strategy. However, I can't say for sure about the reusability of the main.js file.

To load an Aurelia app within a specific tag, you can use the following code:

aurelia.start().then(() => aurelia.setRoot('my-root', document.getElementById('some-element'));

If you wish to load multiple apps on the same page, you may need to have 2 separate main.js files. There is a helpful example in this thread Multiple Aurelia apps on one page that demonstrates how to have two apps on a single page.

In my opinion, apps sharing the same page should have a unified project structure, including one config.js, src folder, dist folder, etc. Conversely, apps that are independent from each other should have separate project structures, with different config.js, src folder, dist folder (and possibly a different Aurelia version). This approach ensures each app's independence and reduces the risk of breaking changes.

Ultimately, this is just my viewpoint. If you require further guidance, you can always reach out to the Aurelia team as they are highly responsive.

I hope this information proves to be helpful!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Node.js error message: Unable to load HTTP module

Recently starting with Node.js, I decided to install the latest version (4.2.1) on my Windows 7 PC. However, when trying to include the HTTP module by writing: var http = require("http"); I'm receiving an undefined error message. Can someone help me ...

Screen rendering can be a challenging task

As I dive into learning how to use THREE.js for creating browser games, I've encountered a roadblock. Every time I attempt to import a model using the code, the screen just renders black. Surprisingly, I've been smoothly coding and running it in ...

Make sure to implement validations prior to sending back the observable in Angular

Each time the button is clicked and if the modelform is invalid, a notification message should be returned instead of proceeding to create a user (createUser). The process should only proceed with this.accountService.create if there are no form validation ...

Using the Github API in javascript, store an image as an image by saving its base64 Data URL

I have a base64 encoded Data URL of a webp image that looks like this: data:image/webp;base64,R0lGODdhAQABAPAAAP8AAAAAACwAAAAAAQABAAACAkQBADs= My goal is to push this image to GitHub using their API in the form of a webp image. To clarify, I want to achi ...

Tips for stacking objects vertically in mobile or tablet view using HTML and CSS

I have been diligently working on a project using a fiddle, and everything appears to be running smoothly in desktop view. The functionality is such that upon clicking any two product items (with one remaining selected by default), a detailed description ...

Encountering issues trying to display state value retrieved from an AJAX call within componentDidMount in React

I recently implemented an AJAX call in my React application using Axios, but I am a bit confused about how to handle the response data. Here is the code snippet that I used: componentDidMount() { axios.get('https://jsonplaceholder.typicode.com/us ...

I am currently working on determining whether a given string is a palindrome or not

I'm currently working on a function that checks whether a given string is a palindrome. So far, my tests are passing except for the following cases: (_eye, almostomla, My age is 0, 0 si ega ym.) This is the function I've implemented: function pa ...

Exploring the functionality of Material-UI's TextField component through role-based testing with React

I currently have some components that contain mui TextFields, and there are two specific scenarios for these components: One TextField is meant for LicenseCode and does not require a label. Additionally, there are several TextFields generated using t ...

Stop procrastinating and take action before the JavaScript function concludes

Currently, I am experimenting with onkeydown events to capture the input value in a textarea, process it through a PHP file using Ajax post method, and display the result in an external div. However, the issue is that whenever a key is pressed, I am unable ...

What causes the ongoing conflict between prototype and jquery?

I have researched how to effectively load both prototype and jQuery together, but the solutions I found did not resolve my issue. My current setup involves loading jQuery first, followed by this specific file: http:/music.glumbo.com/izzyFeedback.js, and t ...

Babel not functioning properly with static class property

I'm utilizing JSDOC along with all its supported npm plugins to generate comprehensive documentation. However, I've been facing difficulties when running jsdoc and parsing JSX files, as it consistently throws an error near the "=" sign as shown b ...

Control the value dynamically with Powerange using JavaScript

I have incorporated the Powerange library into my form for creating iOS style range bars. This javascript library offers a variety of options provided by the author. Is there a method to programmatically move the slider to a specific value using JavaScrip ...

Can we include intricate items within a redux store?

As I delve into developing a React application with Redux, I encountered an unexpected scenario. At one point, we inserted a DOM element within the store, causing issues with the Redux extension that freezes when the action is triggered. Despite this compl ...

Divide a SINGLE BACKGROUND IMAGE in HTML into two separate links of equal size, one at the top and

As a beginner in HTML, I am trying to find a way to divide a background image into two equal sections without using image mapping. I attempted to split the links by setting the style to 0% and 50% to designate the top and bottom halves, but unfortunately, ...

Issues with image loading in Next JS and Cloudinary

I'm currently delving into the world of Next JS and attempting to convert my app into a static site. In doing so, I've opted to utilize Cloudinary for image processing; however, I'm encountering issues with the images not displaying. Next JS ...

Is there a more efficient method for handling this JSON dataset?

After delving into Sitepoint's "Novice to Ninja" and starting to explore jQuery, I can't help but question if there is a more efficient way to write the code I've put together. The resounding answer appears to be "yes." All these cumbersome ...

My controller in AngularJS is having trouble fetching the latest values of the $scope variables

In my code, I've included the relevant snippet below. The base angularJS seems to be functioning properly as the HTML document doesn't display {{}} variables but instead remains blank. I suspect that this is due to the variables receiving a null ...

The G/L account specified in the SAP B1 Service Layer is invalid and cannot be used

I attempted to generate a fresh Incoming payment utilizing the service layer, but encountered this issue G/L account is not valid [PaymentAccounts.AccountCode][line: 1] Here is my JSON: { "DocType": "rAccount", "DueDate& ...

What sets apart a React component from a function-as-component in React?

React is really confusing to me right now. Take this simple react component for example: export default function Foo(){ return( <div> <div>some text</div> </div> ) } I want to add a child compone ...

Pass data to PHP using AJAX

Is it possible to pass the variable rowNumber to the PHP file dataSource in this code? function getData(dataSource, divID,rowNumber) { if(XMLHttpRequestObject) { var obj = document.getElementById(divID); XMLHttpRequestObject.open("GET", dataSo ...