0

I had my code working with ngRoute with no problems to load files by dynamic generate a URL for my views files:

.when('/page/:name*', {
        templateUrl: function(urlattr){
            return '/views/' + urlattr.name + '.view.html';
        },
        controller: 'PageController'
})

but then I got to move to UI Router in order to use nested views, but what is the equivalent of the above code with UI Router? I've tried the following code:

.state('home.pages', {
        url: "/page/:name*",
        controller: 'PageController',
        templateUrl: function(urlattr){
            return '/views/' + urlattr.name + '.view.html';
        }
});

and I'm getting the error

Could not resolve '/page/test' from state 'home'

In my anchor I'm trying to call it by the URL. The link comes from a database that knows URLs but not state names

<!-- I want to load '/views/test.view.html' file -->;
<a href="#/page/test">Link not working</a>
<div ui-view>nested view content</div>
5
  • do you have a parent state home? You are showing home.pages which would be child state of home Commented Jul 27, 2015 at 21:30
  • Yes I do. And it's working fine Commented Jul 27, 2015 at 21:33
  • Where is the urlattr being passed in? I dont see query strings on the url. Commented Jul 27, 2015 at 21:36
  • it's not a query string. I want to take the substring after page/ from the URL. Example 'test.view.html' Commented Jul 27, 2015 at 21:39
  • Ok, just try removing * Commented Jul 27, 2015 at 22:35

1 Answer 1

2

Sounds like you are creating your anchor incorrectly. You should be doing something like

<a ui-sref="home.pages({param: value})">Link</a>
Sign up to request clarification or add additional context in comments.

4 Comments

that won't pass the url param though
I edited to allow passing params. If that is not what you mean, can you show your markup?
Is that a what to pass the URL instead of the state name? The link comes from a database that knows URLs but not state names
Yes, the normal way <a href="/page/test?param=value">Link</a> works. That is why I wanted to see what you were doing.

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.