christopher clark
christopher clark

Reputation: 2103

Basic Router not working in Aurelia

Everything I have tried to do has given me the erorr in the Console. "ERROR [app-router] Error: Route not found: /(…)error"

I don't understand what I could be doing incorrectly.

My folder paths are:

--wwwroot
    |_ src
        |_app.html + app.js
        |_home.html + home.js
        |_mypage.html + mypage.js

My app.html page

<template>    
    <div class="container-fluid">
        <div class="row">

            <div class="col-sm-3 col-lg-2">
                <nav class="navbar navbar-default navbar-fixed-side">
                    <ul class="nav navbar-nav">

                        <li repeat.for="row of router.navigation" class="${row.isActive ? 'active' : ''}">
                            <a href.bind="row.href">${row.title}</a>
                        </li>
                    </ul>
                </nav>
            </div>
            <div class="col-sm-9 col-lg-10">
                <div class="row">
                    <h1>${message}</h1>
                </div>
            </div>
        </div>

    </div>
    <div class="page-host">
        <!-- Route mount point  -->
        <router-view></router-view>
    </div>
</template>

My app.js file is

export class App {
    message = "Hello Pathways";

    configureRouter(config, router) {
        config.title = 'Scotch IG';
        // Use map to set array of possible routes
        config.map([
                { route: ['','home'], name: 'home', moduleId: './home', nav: true, title:'Home' },
                { route: 'mypage', name: 'mypage',  moduleId: './mypage',    nav: true, title:'MyPage' }
        ]);

        // Create a binding to the router object
        this.router = router;
    }
}

I've tried throwing src/ in front of everything to try different folder structures. But I'm starting to think something is wrong with the install.

My config.js under paths is "*": "src/*.js"

Upvotes: 0

Views: 690

Answers (1)

Rayudu
Rayudu

Reputation: 1816

Give path in config.js as below

paths: {
    "*": "src/*",
    "github:*": "jspm_packages/github/*",
    "npm:*": "jspm_packages/npm/*"
  },

This will take care. If you any folder inside src, then give moduleId: foldername/Home.

And one more point if you are using main.js file then check with setRoot to app file like

aurelia.start().then(a => a.setRoot('app'));

Upvotes: 1

Related Questions