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
Only route registered routes #25
Comments
We have exactly the same problem, we stuck on this just couple minutes after you post this issue. Desired outcome for us is that router will hande only routes which passes filter (or are registered by router). |
Oh, that's a bug. We got to fix it.
|
Hi @LDiab @shamotj
As my understanding |
Hi, I think B would be the best option, If a route dont satisfy any registered filter it should be ignored by the Route and the browse should take the default option (If I have understand it). So an app who only uses Riot routes if he wants to show a 404 whenever the user enter in a invalid url, he just needs to use '/..', and in server based urls, the server will handle the 404. Returning false is an interesting option which allows more complex routing and behave, but it can be avoided for now, it can be a "feature request". Thanks for working in this :)
|
@LDiab thanks for your quick feedback. If we use Think this situation: riot.route.base('/app')
riot.route('/', function() { /* home */ })
riot.route('/news/*', function(id) { /* news */ })
riot.route('/..', function() { /* not found */ })
riot.route.start(true)
The last case is a problem. Even if there's existing static page, "not found" route will fire. Does it make sense..? |
Mmmm yes, because you have explicitly registered every route to trough that if you haven't registered it before, so to solve this the user has two options, manage every url in the webapp with this route, non on the server, or not to register '/..' and handle all other request on the server. Alternatively maybe could be added a parameter like a callback to go to the next filter, and if there isn't any other filter execute the expected behavior something like this:
You know? So It would be always the last argument, and it is executed only if the user wants it, this is how Express.js handle this. Like I said if the user executes the calback in the last valid filter, then is saying to the route It needs to handle it by server, maybe a next(true) for a direct 'to server' action could be also very interesting. |
Yeah, sounds good. But I have some concern...
How about just returning |
Just to point out that Express' use of If I understand properly it doesn't seem that riot's router does things differently in terms of route selection: a typical router (Express, Component) loops through the routes, and riot does the same thing as far as I can tell. (On the other hand, riot uses an If I understand properly, what we are trying to achieve here is for a callback to be able to tell the router that it picked the wrong route, and would it please continue to iterate through the list of routes (something Express or other common routers do not support). I think the solution with a simple boolean answers both of these but I'm not sure it's feasible with an @cognitom in terms of API, instead of a |
@shimaore Hi, Yes, It is used by middleware, but, ExpressJs, has as a Coding Standard (Or something like that, sorry my english level isn't high enough) to use Next in every route you register, as they say:
So you can do something like this: And then you in '/admin' take control over the user perms: I think is the cleanest way, but yeah, I use a lot Node.js so all my thoughts are async... EDIT: Sorry I maybe dont explain it quite well, basically with the last example I try to demonstrate that it is really useful, if you want to enter: Because when you enter on one of this two routes, before it hits them, you hit Also, now I see "another problem" it would be awesome to have something like But this would be another 'issue' here in Github I think only if 'more than one route can be hit' Thanks for everything 👍 |
@LDiab I stand corrected, I missed the introduction of
to use that feature. (In previous versions one would have used that middleware in the stack for |
@shimaore No, by adding 'route' you are doing the opposite:
Executing |
But I think we are messing here, there is two things in this Github issue, so I think It should be splitted:
So here would be only the first item. Any thoughts? |
Yeah, at this time, I'd like to merge #26 without |
Alright, apparently I've been spending too much time in middleware and didn't really understand how Express behaves wrt the last callback in a route stack. In the order things are processed:
|
Hi, I think the fix isn't working... I still get the url changed but nothing happens and I have only one url registered like this:
Its the compiled version of my coffeescript, am I doing something wrong? Thanks! |
Fix works for me, here's a snippet from my code, maybe it'll help:
|
Would something like angular does be unacceptable in terms of clicking on links? Any link that specifies a |
@LDiab @cognitom I posted about a similar issue in the Riot Forum today but maybe I should have filed an issue about it here instead. Well, since this one is still open I thought I could share my experience (and solution). What I experienced was that links with relative paths like My solution was to define a base route A side note: using |
@senica I ran into the same issue and ended up using |
Closing this issue because it's related to an old router version. Please update to the latest |
Note: Using Riot 2.3.1
So I was rewriting my webapp which used:
http://example.com#media/id
In the new version the base by default is '#' but it affects every link in the webpage, using or not using '#' so I couldn't click any links because it didn't do anything at all. I really needed to get it working so I finally changed the base to '/' and then the url in the adressbar started to change as I clicked the links but, It does nothing, just works with registered routes, in my case '/media...' after changing the base.
To get it working I needed to register '/..' and then redirect by javascript if the destiny was different from the origin. Here is the code (Which right now doesn't think in queries) I used to get this working If it is of any help:
So I can't find anything to solve it in a more official way. Usually in ExpressJS (Node.js) routes are like (req, res, next), and the next param is to call the next registered route which fits the actual route with his filter. If it doesn't have any other, it makes the default move, which in Express usually would be 404 because It doen't find any route, but here would be to send it to the clicked url.
In less words: When any route doesn't satisfy the asked route, it ""shouldn't do event.preventDefault()"" (Just as an example XD)
Sorry if there is an official way to do this, but I couldn't find it :S
The text was updated successfully, but these errors were encountered: