Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change which files Aurelia-App looks for?

Tags:

aurelia

I've initialised aurelia with

<body aurelia-app>
   ...
</body>

The getting started guide (http://aurelia.io/get-started.html) says that this will, by default, try to load up app.js and app.html

How can I tell aurelia to load up main.js and main.html?

if I do <body aurelia-app="main"> only main.js is accessed and the view isn't shown.

like image 450
Meirion Hughes Avatar asked Jun 17 '15 15:06

Meirion Hughes


1 Answers

When you supply a value for the aurelia-app attribute, Aurelia will load that module and call the configure method that is exported by this module. This is explained in the documentation.

Your configuration must tell Aurelia which module to load for the app root. Here is the example from the documentation:

import {LogManager} from 'aurelia-framework';
import {ConsoleAppender} from 'aurelia-logging-console';

LogManager.addAppender(new ConsoleAppender());
LogManager.setLevel(LogManager.logLevel.debug);

export function configure(aurelia) {
  aurelia.use
    .defaultBindingLanguage()
    .defaultResources()
    .history()
    .router()
    .eventAggregator()
    .plugin('./path/to/plugin');

  aurelia.start().then(a => a.setRoot('app', document.body));
}

What you're expecting to happen isn't the actual behavior. Setting the value of attribute points Aurelia to a configuration module that will point aurelia to the app root. In your case, you might want to do something like this:

index.html

...
<body aurelia-app="configuration">
...

src\configuration.js

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

  aurelia.start().then(a => a.setRoot('main', document.body));
}

And then src\main.js and src\main.html will be loaded as you expect (well, actually it will be dist\main.js and dist\main.html, but the files you're editing are in the src directory).

like image 56
Ashley Grant Avatar answered Nov 24 '22 01:11

Ashley Grant