Abraão Alves
Abraão Alves

Reputation: 803

Aurelia View without ViewModel

To configure a route I need a ViewModel and optionally a View, but many times I see that ViewModel is required only to get a html. As result, I stay with many empty classes in js/ts files, just to make router config work.

The question: is there any way to remove this empty classes and configure routes like this:

config.map([
    { route: ['', '/'], moduleId: 'no-selection.html',  title: 'Select'},
    { route: 'about', moduleId: 'about.html', title:'About'},
    { route: 'contacts/:id',  moduleId: 'contact-detail',  name:'contacts'}  
]);

Upvotes: 4

Views: 724

Answers (2)

Sander Spilleman
Sander Spilleman

Reputation: 639

You can create a generic parameterised route with a generic view-model. In the template you can then use "compose" to display the static html...

add a route to your config

{'views/:page', moduleId: 'views/index'}

in views/index:

export class IndexViewModel {

    private page;

    constructor() { }

    activate(params) {
        this.page = './' + params.page + '.html';
    }

}

in views/index.html

<template>
    <compose view="${page}"></compose>
</template>

Upvotes: 1

Ashley Grant
Ashley Grant

Reputation: 10887

This isn't currently possible, but it is an enhancement we would like to do at some point in the future.

Upvotes: 4

Related Questions