nanndoj
nanndoj

Reputation: 6770

Angular UI-Router with dynamic URL

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>

Upvotes: 0

Views: 161

Answers (1)

GPicazo
GPicazo

Reputation: 6676

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

<a ui-sref="home.pages({param: value})">Link</a>

Upvotes: 2

Related Questions