Routing using iron:router


#1

Hi I am new to using meteor, I am trying to route a html page using the following code;

HTML:

<template name = "zero">
{{#if currentUser}}
<!-- user profile -->
<div id="profile-wrap">
<h1 class="username"><i class="fa fa-user"></i>{{username}}</h1>
<h2 class="email">{{email}}</h2>
</div>
<!-- user's score -->
<div align="center">
<p><span>You Scored 0/12 In The Classification Task (0%) </span><br>
<br>
<img src="tryagain.jpg" id="Pic" height="250" width="300">
<br>
<br>
<br> 
<span>You scored a 0 out of 12!<span id="score">. Try again to get a better score!</span></span></p>
<p>&nbsp;</p>
<p><a href="http://localhost:3000/profile" class="style6">Click Here to Start Again</a></p>
</div>

<!-- end profile -->
{{/if}}
</template>

route:

this.route('zero', {
		path: '/zero',
		template: 'zero'
	});

but i get an error saying "Oops, looks like there’s no route on the client or the server for url: "http://localhost:3000/0.html." and i do not know what i problem is? Any help will be very appreciated!


#2

Hi @kg1745,
Can you edit your post to put the code into a code block?
You can put code in a code block by wrapping it in three backticks ` like so:

```
// Code goes in here
```

Can you also edit to include your route definitions and more of your template code?


#3

oo thank you! didnt know that haha, ye i have edited the question now :slight_smile:


#4

Can you edit in or post your route definitions?


#5

the route definition is;

Router.configure({
	layoutTemplate: 'main_layout'
});

//Routes to navigate throught the website

Router.map(function(){
	//Home page route
	this.route('home1', {
		path: '/home1',
		template: 'home1'

	});

	//Login page route
	this.route('login', {
		path: '/',
		template: 'login'

	});
	
	//Signup Page route
	this.route('signup', {
		path: '/signup',
		template: 'signup'

	});

	//Profile Page route
	this.route('profile', {
		path: '/profile',
		template: 'profile'

	});

	//Score page route
	this.route('zero', {
		path: '/zero',
		template: 'zero'
	});

all the routes above route for ‘zero’ functions but when trying to route to this web page it gives the error.


#6

Router.map??? I have never seen such


#7

router.map is another method of writing routes. all the routes before the route for zero works but when i try to route to 0.html, it gives that error and i dont have any idea what caused this.


#8

Personally I would switch to FlowRouter, I found it a bit easier, and had better SEO packages. Welcome to Meteor.


#9

Is it because your path is /zero and you’re trying to go to /0.html?


#10

IT IS DEPRECIATED ! I recommend use docs at http://iron-meteor.github.io/iron-router/


#11

What you mean? We have been using iron for 3 years , and no problems because we write

Router.route('/', function () {
    this.redirect('/signup')
})
Router.route('signup', function () {
    this.render('signUp_page')
})

not

Router.map(function(){
	//Home page route
	this.route('/signup', {
		path: '/signup',
		template: 'signup_Page'

	});
})	

#12

FlowRouter is deprecated? Oh. Gross.

I liked IronRouter just as good, but had some weird requirements. I switched to flow and prefer it ever so slightly. Both are great.


#13

@engrpeters That’s not the cause of the issue though. The code for map just sets the Router as the context for this in the enclosed function:

While it’s useful to know it’s a deprecated use, it doesn’t help solve the problem on its own

I have a feeling that it’s just zero vs 0 that’s the issue here