I have an app that has tons of routes and controllers. Our app allows people to create projects and manage them. All of the routes except user related ones requires the project id, currently we store the project id in cookie but plan to move it to urls so the scheme will become /PROJECT_ID/project-related-endpoint from /project-related-endpoint
I basically need to add a prefix to all my routes that represents the current project id but it requires too much work. All of the routes need to change, all redirection calls ($location.path()) needs to be re-written so I'm looking for a solid way to solve this problem. Should I override $location.path() that adds the prefix automatically and change the routes manually or is there any better way to handle this problem?
Related
I want to do three things in my application, but I’m not figuring out how I could do that using Next.js router.
The default URL of the application should be 'https://localhost:3000/en'
It should also be possible to have 'https://localhost:3000/es' as a valid URL
Anything different than '/es' should redirect to '/en'
(This parameter will influence on the displayed language of the application.)
Considering those three points, should I create inside pages folder a new folder called language and put my index.tsx file and all the others routes that I have?
Example here
If I do that, what are the rules that I should create on my next.config.js to match with the criteria that I listed above? If not, what could be another approach to solve this?
Hopefully this is not too opinionated but I am wondering if there are best practices regarding location-based SPAs and Internal based SPAs.
Internal based SPAs - track state internally
Location-based SPAs - URL location / Sessions , etc
In one part of my site if a user pastes in the url the search results will show.
However if I should be doing it for areas like admin section.
For instance I am allow users to add inventory to this point
admin -> add new Inventory -> choose center -> choose subcategory -> add inventory.
This is pretty much the flow, however if I would make it location based then on the "add inventory page" I would have to set the
company
center
subcategory
Which would require ajax requests to get all the data and basically every page I would have to do setting up data. It just seems like alot of work that every page has to be fully setup if they are coming from a url.
I am already using stuff like react-router to do my routing but in the end of the day I would to make sure that everything is always setup to the page can basically run standalone.
So maybe in some situations it would be better to somehow just redirect users back to the root of everything instead?
I would recommend using React Context for resolving your problem.
Once authorized, you can set the Provider value to be the user or their permissions, then on each ComponentDidMount or render() or whatever lifecycle hook you choose, you can check the users permissions and then allow the functionalities based on that.
Context values persist throughout routing, so you won't have to worry about updating it all the time (although you probably should if your user has a timed session).
So it is fully possible and probably more effective to use a mix of both internal and location based state management.
What I'd like to do is if someone shits domain.com, hit a certain set of routes, and if you go to site1.domain.com or site2.domain.com, etc, hit a different set of routes. I considered making the subsites a different app, but a lot of components/logic will be shared, just certain parts will be tailored to the subsite.
I'm having difficulty figuring out where and how I should put the logic to figure out if I'm on a subdomain, and thus do an extra API call to get the subdomain's info (as far as I can tell, I just have to use the regular JS window.location object?), and once I have that info, how to modify routes accordingly.
For example, I'd like to have a system where the subdomains can have dynamically created menus, but with the routes being part of the #NgModule decorator, I'm not sure how I can do logic on the routes array prior to it being put in the injector (which is why I assume it's always shown as an array defined outside the class).
I suspect I'm just missing something fundamental about Angular, but I'm not sure what that may be.
Really liking the simplicity and the power of the NancyFX framework, but I ran into something which I cannot find a good solution for; how to route based on subdomains?
For example; I want to define a route that matches something like
{account}.website.com/restofroute
While having other parts of my site react to the normal www.website.com routing. So basically I want multi tenant support in my site based on the host name.
I found some ways to create and hookup a TrieNode so I can match the host header against some pattern and extract the account itself, but I don't see how I can link this up with the routes itself. Somehow I need to do this in the rootnode I think, so I override the GetMatches and add my local captures to it. Local captures are generated by some regex and contain something like {'account', 'www'}.
I thought I could create something like:
Get["/", a=>a.IsWwwRoute()] = parameters =>
Where IsWwwRoute is a method extension looking at the parameters collection for the account parameter that I included using the local captures. If set to 'www' let it pass, otherwise we use another route (which then uses the account parameter). But I cant find the value anywhere (parameters is null).
So what is the best way to add subdomain routing to NancyFX?
I am planning to rewrite my site into CakePHP and after having spent a full week on learning it, I am still not sure how to do good custom routing in CakePHP.
This is what I want:
Keep the current url structure in www.domain.tld/en/dragons.html, or use a www.domain.tld/en/dragons, but not www.domain.tld/en/nodes/dragons.html. And also be able to use controllers on a similar path structure.
There are about 100 static pages on the entire site. I have read into multi-language routing and I think I can do it. I can also make /en/* or /en/:slug route via a PagesControler or a self-written NodesController.
My problem is that I would like to be able to mix and match url's with and without controllers, so actually what I want is that it checks if a :slug is part of the slug-list, there should still be the option to use that url with a controller.
I have created routes for both /en/contact and /en/:slugid, but it seems all queries were routed to my NodesController, even while I explicitly said that /en/contact should be routed to the ContactsController.
How can I instruct Cakephp to keep my current dictorary structure? I read the routes part of the Cakephp book, but it was extremely short and made me a little unsure about the possibility of such routing. If necessary, I'll just write a php-code that prints all routes for all slugs, so I can still write controller-routes with a similar path structure.
If a file exists in webroot (ie. app/webroot/static.html), the .htaccess file will tell Apache to serve that file before loading the CakePHP framework for requests to www.example.com/static.html.
Cake loads routes in a top-down order and will use the first matching route to handle a request. In your case, /en/contact should be above /en/:slugid, else the slugid rule will always win.
If CakePHP's routing does not accomplish what you are after, you can always implement a custom route class (book / example).