In our project we have a bunch of routes such that the original route: routeAction is followed by !route: routeAction like so..
'home': 'homeAction',
'!home': 'homeAction',
No one on the team knows why we do this. Anyone here know? Can't find anything in the documentation about it.
Adding that exclamation mark (!) has nothing with backbone that's why you can't find anything in the doc about it Backbone treats it like any usual URL. But If the project is a little bit too old I think this was used to let google crawl that ajax content this way accessing the route with ! will stay valid and calls the appropriate handler.
Related
I'm fairly new to Next as a framework and I'm trying to determine how best to handle pagination.
My goal is to have urls such as:
/category-one
/category-one/2
/category-one/3
/category-two
/category-two/2
... and so on
*notice the lack of a /1
Next appears to operate through dynamic slugs in the folder/filename e.g.
pages/
[category]/
[page].jsx
However, what I'm struggling to work out, is that how I can have a page template for NON-paginated urls, and one for paginated urls, without essentially copying the file, this ending up with a bunch of extra code to maintain.
My first thought was to see if I could have say:
pages/
[page].jsx
[category]/
[page].jsx
and extend the parent page for the child page, and just add some littles bits to handle the second part of the slug.
However, this doesn't seem to be an option.
I feel like I'm missing something obvious, but I can't seem to find any examples that show a similar setup to what I'm seeking.
I appreciate that the simple answer would be "just have a /1 after the page one and forget the parent page template altogether", but I'd expect that a framework as robust as Next.js would be able to handle something simple like this.
Any help/pointers would be greatly appreciated!
For anybody finding this question and having the same problem, the answer (which was provided by juliomalves in the comments) is exactly what was missing.
Look into optional catch-all routes.
I'm using wildcard-subdomains to handle wildcard subdomains in my express app, so something like subdomain.localhost:3000 would enter the router as /s/subdomain/.
I want to match the main index url of any subdomain, but none of the pages under it.
Essentially, I want a route that would match /s/subdomain/ but not /s/subdomain/page/ or /s/subdomain/page (for clarity, "subdomain" is just a placeholder for any wildcard domain)
This is simple to do in regular regex, but I am unable to use the dot modifier due to express using path-to-regexp. It would be possible for me to generate a router for each user, but I would really like to use something cleaner if it's possible.
Dang, i'm pretty stupid. /s/:target/ works perfectly fine, and creates a neat little target parameter to make things a bit easier. I was totally overcomplicating things by trying to use regex.
I have a promo block, that contains several images and links. Some of them are leading to my site, some to external resources. Currently, i use this piece of code for this links.
<a {{ bindAttr href="link" }}><img {{ bindAttr src="image" }} /></a>
However, this actually reloads a page, and i don't want that in case i'm navigating inside my site. Also, it could mean breaking my app if we encounter some non-existent routes, in case of typos or whatever.
So, what i'm trying to do is to add an action, that checks if the route exists and then do a proper transitionTo, and if the route doesn't exist do some sort of default fallback, but i don't know how to make this check. Have anyone did something similar already?
P.S. I know that transitionTo could accept urls as a parameter, but Ember docs say
It is also possible to pass a URL (a string that starts with a /).
This is intended for testing and debugging purposes
and should rarely be used in production code.
And doesn't help with preventing transition if the route doesn't exist.
You could have a default route that would be a 'catch-all' which you would specify in your router as something like:
this.route('badRoute', {path: '/*pathname' });
at the bottom after you have declared all your routes. When none of your routes match, this will be matched and you can redirect or whatever when it transitions to that route.
I'm quite new to backbone.js and trying to convert a normal javascript/jquery application into backbone MVC. With it I came of Backbone.Router and I'm currently trying to solve my old URL handling with backbone, but there some problems I'd like to discuss with you:
My traditional URL pattern looks like this:
/#/lang=1&page=panorama&cats=13,3,4,6,7,8,9,10,11&pid=4
How could this look like with backbone and how to code it?
The thing is, that my traditional handling allowed me to evaluate my URL string with not caring about the order of the parameters. With backbone this seems not to be possible. For my application its like necessary to pass categories (see cats=..) and so on in the url, to link to a specific app position/state.
I already tried it with the pid (panorama-id), so the patters is like:
/panorama/:id
"panorama" is currently no parameter, but stand for a certain page in the application.
I would be really thankful if someone has got a solution for me.
Best solution: https://github.com/jhudson8/backbone-query-parameters
I'm learning Sammy.js and using it to build a mini-application on top of a REST API I'm working on. I couldn't find this immediately, and I am probably missing something.
I'm using routes like:
this.get("/databases/:name", function () { ... });
I basically want to take the route path and pass it along to my REST API, since they largely match up anyways. I've inspected this within the callback, and found a property called path that contains the full path, including the filename. (i.e. /index.html#/databases/foo)
All I care about is what comes after the #, and I wonder if there is something baked in so I don't have to use this.path.split("#")[1].
You could just look at window.location.hash and strip off the leading #. That should be pretty much the same as pulling information out of this.path.