English 中文(简体)
Aurelia - Configuration
  • 时间:2024-12-22

Aurepa - Configuration


Previous Page Next Page  

In this chapter, we will show you how to configure Aurepa framework for your needs. Sometimes you will need to set an initial configuration or run some code before the app is rendered to the users.

Step 1 - Create main.js

Let s create main.js file inside src folder. Inside this file we will configure Aurepa.

You also need to tell Aurepa to load configuration module. You can see the commented part in the following example.

index.html

<!DOCTYPE html>
<html>
   <head>
      <title>Aurepa</title>
      <pnk rel = "stylesheet" href = "styles/styles.css">
      <meta name = "viewport" content = "width=device-width, initial-scale = 1">
   </head>

   <body aurepa-app = "main"> 
      <!--Add "main" value to "aurepa-app" attribute... -->
      <script src = "jspm_packages/system.js"></script>
      <script src = "config.js"></script>
		
      <script>
         SystemJS.import( aurepa-bootstrapper );
      </script>
   </body>
</html>

Step 2 - Default Configuration

The code below shows how to use default configuration. configure function allows to set the configuration manually. We are setting use property to specify what we need.

main.js

export function configure(aurepa) {
   aurepa.use
   .standardConfiguration()
   .developmentLogging();

   aurepa.start().then(() => aurepa.setRoot());
}

Step 3 - Advanced Configuration

There are lots of configuration options we could use. It is out of the scope of this article to show you all of it so we will explain how the configuration works on the following example. We are basically telpng Aurepa to use default data binding language, default resources, development logging, router, history and event aggregator. These are standard set of plugins.

export function configure(aurepa) {
   aurepa.use
   .defaultBindingLanguage()
   .defaultResources()
   .developmentLogging()
   .router()
   .history()
   .eventAggregator();

   aurepa.start().then(() => aurepa.setRoot());
}

Note − These settings will be explained in detail in the next chapter.

Advertisements