iron-meteor / iron-router

A client and server side router designed specifically for Meteor.
MIT License
1.98k stars 412 forks source link

Router.current().url returns absolute url on first run #1152

Open boustanihani opened 9 years ago

boustanihani commented 9 years ago

Happy new year first :)

I just noticed that calling Router.current().url for the first time returns the absulute URL of a route, whereas any further calls will only return the path.

Reproduction: http://router-current-url.meteor.com/myroute Notice how the value changes when switching between "Home" and "My route" after the first load...

Repository: https://github.com/boustanihani/router-current-url

<template name="defaultLayout">
  <h3>Default layout</h3>
  <nav>
    <a href="/">Home</a>&nbsp;
    <a href="/myroute">My route</a>&nbsp;
  </nav>
  <br>
  <div>
    <span>Router.current().url&nbsp;=&nbsp;<strong>{{currentUrl}}</strong></span>
  </div>
  <br>
  <div style="padding:1em;border:solid;">
    {{> yield}}
  </div>
</template>

<template name="home">
  <h3>Home</h3>
</template>

<template name="myroute">
  <h3>My route</h3>
</template>
Router.configure({
    layoutTemplate: 'defaultLayout',
});

Router.route('/', {
    template: 'home'
});

Router.route('/myroute', {
    template: 'myroute'
});

if (Meteor.isClient) {
    Template.registerHelper('currentUrl', function() {
        console.log('Router.current().url=' + Router.current().url);
        return Router.current().url;
    });
}
emmanuelbuah commented 9 years ago

I'm experiencing the same issue.

fredgreer commented 9 years ago

Same issue here. Is there a fix for this?