meteor - Why does route to home changes after rendering a template? -
i getting started using iron:router package. these project files:
router-example.js
if (meteor.isclient) { //some code } if (meteor.isserver) { //some code } router.route('/', function(){ this.render('home'); }); router.route('/hello', function(){ this.render('hello'); }); router.route('/items', function(){ this.render('items'); }); router.route('/serveritem', function(){ var req = this.request; var res = this.response; res.end('hello server\n'); }, {where: 'server'});
router-example.html
<body> <h1>welcome meteor!</h1> <ol> <li><a href="{{pathfor '/'}}">this routing doesn't work</a></li> <li><a href="{{pathfor 'hello'}}">hello template</a></li> <li><a href="{{pathfor 'items'}}">items template</a></li> <li><a href="{{pathfor 'serveritem'}}">server item</a></li> <li><a href="http://localhost:3000/">hard link works</a></li> </ol> </body>
templates.html
<template name = "home"> <h2>default: '/' brings here</h2> <p>this home template</p> </template> <template name = "items"> <h2>this items template. items page linked using pathfor helper</h2> </template> <template name="hello"> <button>click me</button> <p>you've pressed button {{counter}} times.</p> </template>
so @ home page "localhost:3000", "home" template rendered default, expected. once click on other links: hello template, items template etc. rendered, home link specified using {{pathfor '/'}} helper stops working , have use hard link (localhost:3000) home page. hovering mouse on link shows it's pointing different route.
so doing wrong here?
you can specify route name in order use {{pathfor 'routename'}}
:
router.route('/', { name: 'home', template: 'home' })
look here full example https://github.com/iron-meteor/iron-router/blob/devel/guide.md#route-specific-options
if no name provided, router guesses name based on path
Comments
Post a Comment