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.
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.
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.
Actually, I want to create a web app in node js but when I used to special characters in my navigation path which I wanna go it shows "Cannot get /contest' ". So I want to try a function for sanitizing the path, remove the special characters from my URL and return actual path. How can it be possible in express js to get routing?
Express for Node supports regular expressions in routes.
There is also Router Tester available for you here.
I am using hash-based navigation in my AngularJS app rooted at /.
If a user navigates to my app like this:
http://example.com/?foo
A moment after the page loads, something (possibly Angular) is causing the address bar to look different than I expected.
What I saw:
http://example.com/?foo#/?foo
What I expected to see:
http://example.com/?foo#/
Why is this happening, and can I turn it off?
I'd wager you need to be in 'html5 mode' to not have the hash fragment... though I'm uncertain.
http://docs.angularjs.org/guide/dev_guide.services.$location
$locationProvider.html5Mode(true).hashPrefix('!');
In your app configuration, you can mess with that config param and it'd probably get rid of it.
This appears to be duplicating the hash with the path.
Check out the $location service. It has both path() and hash() methods. The second, duplicated part is the hash, the first part is the path.
Unless you are using html5 mode, all of Angular's part of the URL appears in the fragment. The problem is that Angular doesn't know about the base part of the URL (perhaps the ?foo was needed just to get Angular to load) so it won't attempt to manipulate it, it just puts its own stuff on as a fragment.
I suggest the best thing would be to check $window.location.search for a query string, and if you find one do the redirect to the URL you actually want yourself. You'll still need to do that redirect by assigning to $window.location rather than $location and it will force your angular app to reload but at least you'll end up where you want to get to.
Alternatively you could reconfigure your web server to make the appropriate rewrite, but you may not want to or be able to do that.
Or you tell your users to only use URLs they got from the app, not to try to make them up for themselves.
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.