I want to be able to match paths like this:
/path/anything/goes/here/and/can/be/an/arbitrarily/long/path.
So I tried all of the following:
Router.route('/path/*', function(){
this.render('home');
});
I also tried the path: '/path/:something(*)' and I also tried specifying the path in the second argument options object to Router.route: {path: '/path/*', action:myActionFunction} along with an action function. I even tried using Router.map instead of Router.route, as prescribed in both of the following:
https://gentlenode.com/journal/meteor-11-iron-router-cheatsheet/18
http://www.manuel-schoebel.com/blog/iron-router-tutorial
But still, going to the /path/anything/goes/here doesn't work. It takes me to the default iron:router error page:
Oops, looks like there's no route on the client or the server for url: "http... localhost:1710... /path/this/should/work/according/to/the/above/links."
Any help is appreciated, thanks.
Try
'/(.*)'
or
'/path/(.*)'
if the url really is domain.com/path/
I serve routes from '/(.*)' via look up on a collection of documents from this.params
If you need any routes prior to a catchall put the catchall route in a Meteor.startup and have your finely grained defined routes prior in your router file client side.
Hope this helps you.
Related
I am trying to display a URL with a paramter in Meteor like so:
http://localhost:3000/test/123
My routes.js contains the following:
Router.route('/test/:x1', function () {
this.render('test', {
to:"main",
param:this.params.x1
});
});
and main.html the following template
<template name="test">
<h2>Test {{param}}</h2>
</template>
However, when I access http://localhost:3000/test/123 I get the following error message:
Oops, looks like there's no route on the client or the server for url:
"http://localhost:3000/test/123."
I have pretty muched copied this verbatim from the ironrouter docs. Other issues Stackoverflow, like Meteor deploy Iron:Router "oops looks like there's no route on the client or the server for url" does not seem to address exactly this issue
So I solved the problem in a somewhat inconclusive way. As was pointed out by one of the commentors, the code in itself works, but not in my application. So I created a new application and transferred the code, line by line, to the new application, and it kept on working. Not all the code was displayed above, but the parts that were omitted should not have affected this problem. I still don't know though what triggered the problem in the first place.
When you create a wildcard URL in iron:router for meteor the pathFor Template helper but also Router.go and Router.routes[routeName].path() seems to be broken.
This is our route:
Router.route('/:urlQuery*', function(){
this.render('ourTemplate');
}, {
name : 'ourRoute',
});
To accessing a generated url to this we tried the following:
Router.go('ourRoute', {urlQuery : 'test'});
Router.go('ourRoute', {urlQuery : ['test']});
Router.go('ourRoute', {urlQuery : null});
Router.go('ourRoute', {urlQuery : false});
Router.routes.ourRoute.path({urlQuery : 'test'});
Router.routes.ourRoute.path({urlQuery : ['test']});
Router.routes.ourRoute.path({urlQuery : null});
Router.routes.ourRoute.path({urlQuery : false});
And - of course - also we tried the {{pathFor}} Template-Helper.
Every of these lines of code throw the same errors:
Uncaught Error: You are trying to access a wild card parameter at index 0 but the value of params at that index is undefined
I did not find any reference in the iron:router guide so my question is: How to generate a URL in iron:router with a wildcard as parameter ?
Looks like Iron Router is using path-to-regexp but the format is a little different when used in Iron Router and not very clear. Try this...
Router.route('/:urlQuery(.*)', function(){
The (.) will tell it to take the param name, and repeat it 0 or more times. Just urlQuery is breaking the name I think, and making it part of the regex. Now if you want to pass an array of mulitple objects to Router.go, you will have another issue...
Router.go("our.route", {urlquery: ['test', 'another']});
Produces a URL that looks like this...
http://localhost:3000/test%2Canother
but that's a different issue I don't have an answer for yet. Perhaps for sending multiple's in Router.go, a better way would be to concat them yourself. Looks like iron router and path-to-regexp are not fully integrated yet?
In a Template Helper I get the current path from Iron.Router (iron:router) as follows:
Router.current().route.path(this);
This works fine, unless the route path does contain parameters (e.g. /client/:_id/edit). In that case the path() function returns null.
How do I get the current path within a Template Helper, when the route contains parameters?
There are posts around covering the issue but the solution mentioned there seem not to fit.
I'm using Meteor 1.1.5 with iron:router1.0.7
According to this iron-router/issues/289 there are problems when the path contains parameters. The suggestion to use Iron.Location.get().path This works well for me.
I am updating my website to a Meteor application with iron-router, and need to change my urls. The old scheme had capitalized page names like this:
mysite.com/Contact
but I've changed everything to be lowercase:
mysite.com/contact
That contact route isn't complicated, so it's set up like this:
this.route('contact');
but I want the /Contact url to be redirected. I know I could just do this:
this.route('Contact', {
onBeforeAction: function() {
Router.go('contact');
}
});
but it's so much messier. I'd prefer to do something like this:
this.route('contact', {
path: ['/contact', '/Contact']
});
where the route simply is mapped to multiple paths.
Is there a feature like this? Or is my onBeforeAction the best I'm going to get?
https://github.com/EventedMind/iron-router/blob/devel/DOCS.md#dynamic-path-segments
You can use a Regular Expression for your path segment (see the last example in the Dynamic Path Segments link).
Your path would be:
this.route('contact', {
path: /contact/i
});
Where the 'i' after the forward-slash is the regular expression modifier to be case insensitive allowing you to accept any variation of 'contact' (whether cOntact, Contact, or conTACT).
See http://www.w3schools.com/jsref/jsref_regexp_i.asp for details on the RegEx modifier.
I just cant get this to work...
I have the following routes:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("*.html|js|css|gif|jpg|jpeg|png|swf");
routes.IgnoreRoute("{*favicon}", new { favicon = #"(.*/)?favicon.ico(/.*)?" });
routes.MapRoute(
"Default", // Route name
"{lama}/{controller}/{action}", // URL with parameters
new { controller = "Home", action = "Index", lama = "en-gb" } // Parameter defaults
);
And once I load the page.. I have a img element that tries to retrive the following url:
css/img/backgrounds/slide1_2048x1280.jpg
But the image wont show up and if I check my console I get the following error:
GET {my localhost}/cn/Home/css/img/backgrounds/slide1_2048x1280.jpg 404 (Not Found)
I have such a hard time understanding the route-system.. is there anywhere I can read ALOT more about this?.. And could somebody please help me with this single problem then that whould be very appreciated!
I think have fallen foul of relative urls in your html.
Since you haven't said whether this is Razor or Aspx; I'm just going to go with Aspx.
When you write the img tag it seems that you might be doing:
<img src="[relative_path_to_file]" />, using the path of the img relative to the page.
If that doesn't start with / then it's almost certainly the case that you will end up with issues, especially since MVC URLs don't map to the path of the actual page.
What you want to do is to use Url.Content("~/[full_path_to_file]") which will ensure that an absolute path will always be used.
On another note - you really do not need to write all these ignore routes for files that exist on disk. By default, the routing engine will not route existing files - you have to set routes.RouteExistingFiles = true in the RegisterRoutes method in your global in order to route files that already exist; so I think you should get rid of them.
i usually hit up 1) stackoverflow (obviously!), and 2) the msdn docs are pretty good:
http://msdn.microsoft.com/en-us/library/dd410120.aspx. But i usually end up googling for specifically what i need =)
However, looks like you're trying to setup a route to ignore certain filetypes?
i found this article that gives some good ideas on how to handle this.
I've only blocked one or two filetypes before, and i made one line per filetype. Not sure if you can make one line that has extensions delimited by pipe (|) like you're doing (i could be wrong!)
routes.IgnoreRoute("{*allaspx}", new {allaspx=#".*\.aspx(/.*)?"});
routes.IgnoreRoute("{*allswf}", new {allswf=#".*\.swf(/.*)?"});