magic route for presenter in nette framework - nette

Is it possible to create magic route with nette route ?
what i mean of magic route is i dont need to declare any route array on routelist... but when i type address on browser address bar such as :
http:somesite.com/product/detail/123.
it would point to presenter product -- renderDetail
(this magic route is known in other framework, and i think for some reason it would make complicated if i would type every single action/presenter redirection on routelist array)
thanks in advance.

Do you mean $router[] = new Route('<presenter>/<action>[/<id>]', 'Homepage:default');?
It's in the documentation: https://doc.nette.org/en/2.3/routing#toc-route.

Route from Matěj is working. You just need to type SomePresenter::actionTwoWords as some/two-words in url.
But don't construct urls by hand, use {link} macro in latte templates or Nette\Application\LinkGenerator in code.

Related

Dynamic Routing NextJS with optional paths

Here is the issue I am trying to solve with creating dynamic routes in NextJS.
-products
   -[category]
       -[size]
          -[product]
The issue is some products don't have a size parameter and would need to bypass this parameter to get to the product landing page. Here is an example of the different routes I would like to have:
/products/ceiling-lighting/2x4/light-one
/products/ceiling-lighting/2x4/light-two
/products/ceiling-lighting/2x2/light-one
/products/ceiling-lighting/2x2/light-two
/products/light-switch/switch-one
/products/light-switch/switch-two
Is this possible to do with dynamic routes?
Nope it will not work, you have to pass required number to parameters/segments to reach that specific dynamic page, but as juliomalves said, you can use catch all routes, after using this you will get your parameters in the form of array and you can navigate programmatically depending on number of parameters or whatever logic you want.

How do I localize routes with next.js and next-i18next?

I need to change the name of the route when I change the language. For example, I have a route /en/career but when I change to Czech language, I need a route /cs/kariera. Basically I need the URLs to be localized. Right now, when I'm on /en/career and change language to cs, I get /cs/career. This page should not exist at all and when I render the page on server, I correctly get 404. Can I do something like this with next-i18next package? If so, how?
I found this package https://github.com/vonschau/next-routes-with-locale which probably does exactly what I need but it's apparently no longer maintained and doesn't work under next.js 8.
What I did eventually was to use next-routes package and defined specific route for every page, such as:
module.exports = routes()
.add('en-career-listing', '/en/career/:listing', 'career/listing')
.add('cs-career-listing', '/cs/kariera/:listing', 'career/listing')
.add('en-career', '/en/career', 'career')
.add('cs-career', '/cs/kariera', 'career')
.add('en-our-story', '/en/our-story', 'our-story')
.add('cs-our-story', '/cs/nas-pribeh', 'our-story')
And I also had to create a custom Link component based on next/link where I manually added the language to URL.
next-i18next supports this functionality, it called locale subpaths.
You need to configure: new NextI18Next({ localeSubpaths: 'foreign' }), and then use the Link & Router that NextI18Next instance has on it, not the next/router.

Need help for routing in asp.net webform

i want to achieve few redirection like
when user will type this www.mysite.com/label/uk or www.mysite.com/label.aspx/uk then my labeluk.aspx will load or
when user will type this www.mysite.com/label/us or www.mysite.com/label.aspx/us then my labelus.aspx will load or
when user will type this www.mysite.com/label/fr or www.mysite.com/label.aspx/fr then my labelfr.aspx will load.
so please tell me how do i define pattern for routing like
RouteTable.Routes.MapPageRoute("Source1", "label/{ID}", "~/labeluk.aspx");
RouteTable.Routes.MapPageRoute("Source1", "label/{ID}", "~/labelus.aspx");
i am not being able to figure out how to achieve it by routing. please help me to form the maproute. thanks
You can look into URL Rewriting on the web or SEO Urls
http://www.codeproject.com/KB/aspnet/URL-Rewriting-in-ASPNET.aspx
you could do something like this..
keep one route (in Global) as
RouteTable.Routes.MapPageRoute("Source", "label/{ID}, "~/label.aspx");
so all will resolve /label.aspx, then on label.aspx check ID param e.g.
Page.RouteData.Values.ContainsKey("ID")
and depending on whether it's uk, fr or us do
HttpContext.Current.RewritePath("/labeluk.aspx", false);
alternatively not even need to have /label.aspx just check ID param in Global and do RewritePath there

Drupal pathauto usage

I have a node called artists. It has a field called shortname. I want to have it so that when I add an artists with shortname = 'foo' you can navigate to http://bar.com/foo/ and it will show that artist's node.
What's the magic configuration in pathauto to make this happen?
You need The path auto which requires the token module. You'll need to set up your path using the [title-raw] token. Which should be used with care as node titles could inject bad stuff into your URLs.
It's not a good idea to have http://example.com/[title-raw]. You'll end up with possible name collisions. Try http://example.com/artist/[title-raw]

Drupal 6 Views 2 using Node Path as an argument

Please consider helping a Drupal noob who is in danger of tearing out what hair I have remaining.
I have a view that I want to add an argument to so that it only displays the details of the specified product. Since I'm using URL aliasing the argument is in the form of shop/product1, shop/product2 etc. However, when I go to add an argument node path (which is what I have set to shop/product1 etc is not listed) the only I could use is Node: Nid but that doesn't work because my argument is not a node id but a path alias.
The workaround I've been using is to create a CCK field to store my node path and then create an argument using the CCK field. Is this the only option?
Regards,
Sean
One way to do this would be to create a custom module and define your own callback which would then work out the NID from the path and pass that as an argument to the view using views_embed_view.
There are some contrib modules which allow you to filter by PHP code which would probably do as well.
I believe you can still use NID as the argument, as that is what's in the actual path even though you are displaying an alias in the address bar.

Resources