Clare Barrington
Clare Barrington

Reputation: 1155

Dynamic Routing in Aurelia - Alter Title

    { 
        route: 'content/:id',
        name: 'Details', 
        title: 'Details',
        viewPorts: { main: { moduleId: './admin/content/details' }, aside: { moduleId: './admin/content/aside' } }, 
        settings: { menu:menuSection.content, access: { controller: 'content', action: 'get' } }
    },
    { 
        route: 'content/:id',
        name: 'Add', 
        viewPorts: { main: { moduleId: './admin/content/details' }, aside: { moduleId: './admin/content/aside' } }, 
        settings: { menu:menuSection.content, access: { controller: 'content', action: 'get' } }
        title: 'Add',
        href: 'content/0',
        nav: true
    }   


    import {Router} from 'aurelia-router'; 

    activate(){
        if (this.id === 0) {
            this.router.title = "Add";
        } else {
            this.router.title = "Edit";
        }
    }

I am trying to alter the Title as its currently saying 'Add' for both new and updated content. I've tried routeConfig as well (which threw an error: Unhandled promise rejection TypeError: Cannot read property 'navModel' of undefined), just wondering if I am close, to finding the right code? Do I need to do some sort of push this.router.push?

I believe I may be required to do something with UpdateTitle:

class UpdateTitle {
    run(routingContext, next, routeConfig) {
        var instr = routingContext.nextInstructions.find(i => i.params.id !== undefined && i.params.id !== 0 && i.params.id !== '');
        if(instr !== undefined) {
            Unsure what to do here?//routeConfig.navModel.title("TEST");
            debugger;
        }

        return next();
    }
}

Upvotes: 3

Views: 1069

Answers (1)

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35134

If you want to change the title from activate function, try

activate(params, routeConfig) {
    routeConfig.navModel.title = 'Edit';
}

Upvotes: 1

Related Questions