0

I'm playing with angular trying to create some routes without specifying statically the paths

I have the following ng-routes now:

route
.when("path/of/first/file",{templateUrl: "path/of/first/file.html"})
.when("path/of/second/file",{templateUrl: "path/of/second/file.html"})
.when("path/of/third/file",{templateUrl: "path/of/third/file.html"})

As you can see in this example there's a fixed rule for each file:

path/of/%dynamic_path%/file  -> path/of/%dynamic_path%/file.html

So i should have something like a regexp:

route.when("path/of/(.*)/file",{templateUrl: "path/of/$1/file.html"});

I want be able to add paths without having to specify them in the router configuration ( suppose I have thousands of files ). Is there something that will allow me to do this in angular ng-route or ui-route?

6
  • 1
    You want dynamic routing, see this Commented Dec 5, 2016 at 14:37
  • i've tried that but it seems that the function of templateUrl is processed only at config time. So it's valid for a single route Commented Dec 5, 2016 at 14:39
  • 1
    It was my fault. I fixed my errors and it works now ! :D thanks Commented Dec 5, 2016 at 14:49
  • 1
    if you add it as an answer i'll accept it Commented Dec 5, 2016 at 14:50
  • 1
    Excellent, and nah the answer was already provided ;) Commented Dec 5, 2016 at 14:52

1 Answer 1

0

You want dynamic routing, see this – RamblinRose

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.