Comments (8)
same here, i think it works with path like /posts/:_id if there's no post's id found it renders notFoundTemplate
but if there're no path pre define in Router.map it wont work right ?
from iron-router.
It works on randomness URL that wasn't setup in Router.map.
Any code of your example?
If you can duplicate the case you encountered in a test repo, it will be easier to find the problem.
from iron-router.
Add a catch all route at the end of your routes with a path of '*'. The template will be the same notFoundTemplate. Inside of an existing route, if the data function or value is falsy and you've specified a notFoundTemplate the render method will automatically render it.
Sent from my iPhone
On Aug 19, 2013, at 7:05 AM, crapthings [email protected] wrote:
same here, i think it works with path like /posts/:_id if there's no post's id found it renders notFoundTemplate
but if there're no path in Router.map it wont work right ?
—
Reply to this email directly or view it on GitHub.
from iron-router.
Let me expand from my iPhone response above. There are two cases for a notFoundTemplate: 1) The route exists but there is no record found given the current route (e.g. /posts/5 and post 5 does not exist); and 2) The route does not exist at all (e.g. /bogus/route).
Case 1: Data not found: The render method takes care of this automatically, as long as a notFoundTemplate
is defined on the route or RouteController. It determines whether a record is found by checking whether your data function or value returns a falsy value. For example:
Router.map(function () {
// this route will always render the notFound template because the data function always returns false.
this.route('post', {
path: '/posts/:id',
data: function () { return false; },
notFoundTemplate: 'notFound'
});
});
Case 2: Route does not exist: You need to define a catch all route at the end. This is probably something that should be handled automatically by the router given you pretty much do it every time.
Router.map(function () {
/* all of your actual routes go here */
/* at the bottom define your catch all route */
// matches all urls but doesn't get called until all previous routes have been tested
this.route('notFound', {path: '*'});
});
from iron-router.
If someone could update the example and README that would be awesome :-).
from iron-router.
Will do after computer comes back.
from iron-router.
Thanks @cmather for the timely response. Works great!
from iron-router.
ah nice it works.
from iron-router.
Related Issues (20)
- Redirect urls with trailing slash "/" to urls without slash
- abort unload HOT 1
- Meteor, Iron router: Render makes the page to shake
- Parameters can't have *s in them
- post to serverside route forces client to the posts action url HOT 1
- undefined routes terminate web socket connection
- Iron router Issue with spiderable HOT 4
- can be read from a controller, variables from another controller?
- Defining routes using arrow functions doesn't work HOT 1
- Path name with '/' inside it... HOT 1
- Request entity too large error
- Errors prevented startup: W
- meteor iron:router not working HOT 1
- Dynamic Imports with Iron Router HOT 10
- Able users to save audio files for offline viewing HOT 2
- How to use pathFor have id like {{pathFor route='index.resource.show'}}/{{data._id}} HOT 2
- Subscription lost after a few minutes HOT 1
- Supporting newer versions of Meteor with compat packages
- ERR_OUT_OF_RANGE
- why async, promise?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iron-router.