Aurelia 1.0 routing configureRouter never called
Asked Answered
A

2

5

I tried to follow some tutorials on aurelia.io routing like this one http://www.tutorialspoint.com/aurelia/index.htm

I implemented a configureRouter method in my App class but it s never called

app.js

export class App {


        constructor()
        {
          console.log("app");
        }

        configureRouter(config, router){


          console.log("configureRouter");

          config.title = 'Aurelia';

          config.map([
              { route: ['','home'],  name: 'home',  
                moduleId: './components/home/home',  nav: true, title:'Home' },
              { route: 'about',  name: 'about',
                moduleId: './components/about/about',    nav: true, title:'About' }
          ]);

          this.router = router;
        }
    }

app.html

    <template>

      <nav>
          <ul>
            <li repeat.for = "row of router.navigation">
                <a href.bind = "row.href">${row.title}</a>
            </li>
          </ul>
      </nav>

    <router-view></router-view>
    </template>

As far as I understand, the configureRouter method in app.js is supposed to be called automatically when router-view is detected in the template, but it s not the case (and I dont get any errors in chrome console)

Any ideas?

Asparagine answered 2/9, 2016 at 14:1 Comment(0)
S
4

Didn't read the tutorial, but it seems to work on my machine, can it be that something is not setup correctly in your index.html?

See here for a working sample of your code (using chrome): https://gist.run/?id=49f3aa8ac6cb72f2efc22c3073bc42d8

Is that also not working on your machine?

Btw. checkout the Aurelia skeletons, they are a easy starting point https://github.com/aurelia/skeleton-navigation

Stereoisomerism answered 5/9, 2016 at 6:43 Comment(1)
Yes, I was using the basicConfiguration, after changing to standardConfiguration it worked. aurelia.io/hub.html#/doc/article/aurelia/framework/latest/…Asparagine
C
10

I had a similar problem but turns out that if there is no <router-view></router-view> in the template the configureRouter method is never called. Even though you found your solution but maybe other people might find relief in this solution also

Source: https://www.niclassahlin.com/2016/03/13/aurelia-router-configuration-caveat/

Cymose answered 8/2, 2017 at 20:25 Comment(1)
This has tripped me more than once, and both times ended up here.Annatto
S
4

Didn't read the tutorial, but it seems to work on my machine, can it be that something is not setup correctly in your index.html?

See here for a working sample of your code (using chrome): https://gist.run/?id=49f3aa8ac6cb72f2efc22c3073bc42d8

Is that also not working on your machine?

Btw. checkout the Aurelia skeletons, they are a easy starting point https://github.com/aurelia/skeleton-navigation

Stereoisomerism answered 5/9, 2016 at 6:43 Comment(1)
Yes, I was using the basicConfiguration, after changing to standardConfiguration it worked. aurelia.io/hub.html#/doc/article/aurelia/framework/latest/…Asparagine

© 2022 - 2024 — McMap. All rights reserved.