2

I want to make routes to access user profiles and pages which made by users like belows.


http://example.com/username http://example.com/page_url

This should identify in the routing process by sending a request to backend API. How to gain this with AngularJS v1.4.8?

Current situation. (only working for usernames)

    .when('/:username', {
        templateUrl: 'app/views/profile.html',
        controller: 'UserProfileController',
    })

what I want to make

    .when('/:username', {
        templateUrl: select dynamically,
        controller:  select dynamically,
    })

I have defined separate controllers and views for profile and page entities. HTML5 Mode also enabled

 $locationProvider.html5Mode(true); 

1 Answer 1

1

Why complicate something that can be simple?

Just make one route to handle both cases, make request in resolve and depending on result render different component directive in template using ng-if.

I see no need for some complicated solution with dynamic routing solution.

But if you really, really wish to do so it is possible with ui-router. Just use onEnter event and redirect to different route after getting response. Or do so inside controller.

Just make ajax call and then use $state service to do something like this:

$state.go('userprofile', params, {notify: false});
Sign up to request clarification or add additional context in comments.

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.