baseURI not valid in decorateCooked

api.decorateCooked($elem => {
    var uri = $elem[0].baseURI;
});

uri is not consistent. It has one of the following values, with about equal frequency.

What do you want to achieve exactly?
I’m (still, unfortunately) not a code wizard, but that looks like a race condition.

It may be irrelevant since I don’t know what you want to do, but just in case, what about trying to write your code in

api.onPageChange(() => {
    // just some example code if you need to know on which page you are
    const router = api.container.lookup('service:router');
    console.log(router.currentRoute.name);
}

?

1 Like

I’m trying to do this:

I think I can use window.location.href instead, but thought I’d point out the inconsistent behavior.

I’m very new at this and don’t understand when I should use decorateCooked and when should I use onPageChange as you suggest, and what other events there might be.