Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routes not working if placed inside “if (Meteor.isClient)” #897

Closed
ghost opened this issue Oct 7, 2014 · 8 comments
Closed

Routes not working if placed inside “if (Meteor.isClient)” #897

ghost opened this issue Oct 7, 2014 · 8 comments

Comments

@ghost
Copy link

ghost commented Oct 7, 2014

Environment: iron:[email protected] with meteor 9.3.1.

<--- html --->

<head>
  <title>ironman</title>
</head>

<body>
</body>

<template name="hello">
  <p>Hello.</p>
</template>

<--- js --->

if (Meteor.isClient) {
    Router.route('/', function() {
        this.render('hello');
    });
}

The route is not working in the above case. However, it works properly if route is placed outside "if (Meteor.isClient) {".

@cmather
Copy link
Contributor

cmather commented Oct 7, 2014

The 404 not found code has been removed but not released yet. But with that said it's probably generally better to define your routes outside of a client block so the server knows about them. In the future the line between client and server routes will probably blur.

On Oct 6, 2014, at 8:31 PM, Anish167 [email protected] wrote:

Environment: iron:[email protected] with meteor 9.3.1.

<--- html --->

<title>ironman</title>

Hello.

<--- js --->

if (Meteor.isClient) {
Router.route('/', function() {
this.render('hello');
});
}
The route is not working in the above case. However, it works properly if route is placed outside "if (Meteor.isClient) {".


Reply to this email directly or view it on GitHub.

@rambo-panda
Copy link
Contributor

Q1:

 Router.route('/', function() {
      this.render('hello');
 });   // it can work

if(Meteor.isClient){
  Router.route('/', function() {
      this.render('hello');
  });
}  // it can't work

if(Meteor.isServer){
  Router.route('/', function() {
      this.render('hello');
  }); 
}  // it can't work

Q2: it's my project tree
client
  test.js
  test.html
  test.css
server
   test.js
route.js
//  it can work
client
  test.js
  test.html
  test.css
server
   test.js
   route.js
// it can't work

there is the route.js 's code:
 Router.route('/', function() {
      this.render('hello');
 }); 

@ghost
Copy link
Author

ghost commented Oct 7, 2014

Thank you guys.

Also, I am trying to create a route for the application in a smart-package.
Here's some code for the smart-package:

<--- package.js --->

Package.onUse(function(api) {
  api.versionsFrom('[email protected]');
  api.use(['underscore', 'iron:router', 'templating'], 'client');
  api.addFiles(['mypack.js', 'mypack.html'], 'client');
});

<--- mypack.js --->

Router.route('/a', function () {
  this.render('mypackTemplate');
});

<--- mypack.html --->

<template name="mypackTemplate">
  <p>Hello there!.</p>
</template>

So, as per your comments it is not possible to declare routes in a smart-package as 'mypack.js' would be available only on client or server?

@boustanihani
Copy link

@cmather could you shortly tell us for what reason the server should know about client routes ? Thanks.

@rambo-panda
Copy link
Contributor

@Anish167

console.log(Package.onUse) // undefined

// So unexpected  
// I was a meteor's beginner  there's my meteor infos:
// meteor's version  0.9.3.1
// OS  mac 10.9.5

@tmeasday
Copy link
Contributor

@cmather it seems like this is coming up a bit. I've opened #928 to make sure this is clear in the guide.

@boustanihani - there are many reasons but the simplest is so you server can write the paths of such routes (e.g. in emails). Is there any reason why not?

Closing this. You should define routes globally.

@awgneo
Copy link

awgneo commented Mar 3, 2015

Are non-global routes supported yet? It would be essential to allow this in a modular plugin system (similar to rails) where plugins (/packages) can apply additional routes to the overall system.

@davidefendi
Copy link

good day..>>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants