3

I was wondering, is there a way to dynamically route the user to a specific page based on a certain parameter? For example, I may have a url that look something like this:

http://localhost:8080/admin/{{id}}/home-page.html

Here are examples of how I would want it to look like:

http://localhost:8080/admin/13/home-page.html

http://localhost:8080/admin/9/home-page.html

And based on each URL, I would navigate the user to the home-page.html file, but the data displayed on home-page.html would differ based on which id I pass in. I tried to look at https://stackoverflow.com/a/30874018/1871869 as a guide but I can’t seem to figure out where to put the $routeParams when code because unless I create another controller/page prior to home-page.html, only then can i perform the redirection. Is there any way to accomplish this? Thanks!

2 Answers 2

2

If you're using $routeProvider you can use :param

So for your URL about you could do

.when('/admin/:ID/home-page.html')

in your $routeProvider. Then ctrlAs.ID will be the value of your route.

If you add a question mark at the end, then that route parameter becomes optional, i.e.:

.when('/admin/:ID?')

will work with localhost:8080/admin or localhost:8080/admin/15

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

Comments

1

This might help you. Please look into this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.