Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Conversation

litera
Copy link

@litera litera commented Jan 22, 2014

Adds support for route parameters with regular expression constraints:

/route/:parameter:regex/continued

This makes it possible to create two seemingly similar but different routes i.e.

/user/:id:\\d+/:name?
/user/:name:[a-z]+

Where parameter :id has numeric regular expression constraint and :name in second route has a letter constraint. Double backslash has to be used because single one is stripped out by Javascript as it's an escape character and since "d" doesn't need escaping, it gets stripped out. We have to use double to preserve single backslashes.

Route constraints work as follows:

  1. parameters with constraints can't be optional or greedy
  2. constraint regular expression can't have capture groups as all "(" and ")" are being escaped anyway (existing functionality)
  3. regular expressions can't have forward slashes ("/") in them as they're route segment delimiters

Added support for route parameter regular expression constraints
@caitp
Copy link
Contributor

caitp commented Jan 22, 2014

this is pretty cool, but it definitely needs some tests. I think these tests should be pretty easy to write. Also, it would be good if it looked a bit more like the angular-ui/ui-router regexp parameter rules, just so that there's a bit more consistency and it's easier for people to switch between them if they feel they need to.

Other than that, LGTM, so put together some tests and we can probably get this into 1.3. I believe a new router is being planned, so this behaviour will probably be desirable there too, but I don't think I have the planning documents for the new router on me.

@jumph4x
Copy link

jumph4x commented Mar 9, 2014

Didn't make it into 1.3 beta, did it? :(

@colszowka
Copy link

+1 on adding tests and shipping this!

@mdmunir
Copy link

mdmunir commented Sep 28, 2015

up 👍
use double colon its look not good for me. How about this format

users/:id<\\d+>/:name
users/:action<login|logout>

@mdmunir
Copy link

mdmunir commented Oct 3, 2015

or better syntax

users/{id:\\d+}/posts
users/{action:(login|logout)}

@litera
Copy link
Author

litera commented Oct 4, 2015

I don't think curly braces are a better choice here, as Angular routing doesn't use them to embrace whole URL segments... That's .net's syntax. I proposed double colon as that's an identifier of a variable in segment so could as well serve as a separator of additional properties (like regexes). Your first suggestion of using less/greater-than characters is in my opinion also a better choice than curly braces.

So all of these are arguably better, worse, usable or unusable.

@bisdg
Copy link

bisdg commented Nov 5, 2015

Hi,

We are trying to use this new feature in our app but getting the same error as earlier. Angular is still not able to identify the regular expression differentiating a string from an integer. Can you please share some code-snippet or the correct way to pass the regex in route params?

We are using angular v1.2.6 and just want this fix to work for having regex support.

Thanks in advance!

@litera
Copy link
Author

litera commented Nov 5, 2015

@bisdg what error are you talking about? Can you provide more information?

@bisdg
Copy link

bisdg commented Nov 5, 2015

Hi litera,

I think the problem was in our code where the regular expression was not correct and not matching with the location url.

Thanks a ton for your reply.

@joeesteves
Copy link

Hi,
Does anyone knows when this feature will be included ?

thanks,

@migaber
Copy link

migaber commented Jan 3, 2016

Please Check this feature as it's really helpful

@asCii88
Copy link

asCii88 commented Feb 8, 2017

+1

@Planet910
Copy link

Why this feature has not been accepted? It's really helpful!

@izikaj
Copy link

izikaj commented Jan 23, 2018

Still waiting for it :(

@petebacondarwin
Copy link
Contributor

Still waiting on tests....

@chulian1819
Copy link

this is a basic feature from 2014 and is still OPEN! angular it's just not production ready by any means with the lack of so many basic features like this one (and many others than are stopping me from finishing the prototype that I was going to show to the company's architect to select ang as our new frontend framework, but right now will have to scarp it and pick react or vue because ang is more trouble than is worth)

@llexical
Copy link

@chulian1819 angular.js is no longer in development if you want to use Angular then look at https://angular.io/ which is more updated and still in development. React and Vue are also good choices :).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.