M
M
mortyyyyy2015-10-25 17:35:02
Angular
mortyyyyy, 2015-10-25 17:35:02

How to correctly implement a tab change when following a direct link?

There is such a routing

app.config(function ($routeProvider) {
        $routeProvider.
            when('/', {templateUrl: './src/tmp/profile.html'}).
            when('/friends', {templateUrl: './src/tmp/friends.html'}).
            otherwise({redirectTo: './src/tmp/profile.html'});
    });

and a tab changer
app.controller('TabController', function ($location) {
        this.tab = 1;

        this.setTab = function (tabId, path) {
            this.tab = tabId;
            $location.path(path);
        };

        this.isSet = function (tabId) {
            return this.tab === tabId;
        };
    });

When you click on a tab, everything works fine, but when you click on a direct link, for example, to index.html#/friends, nothing happens with the tabs, how can I solve this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2015-10-26
@streetflush

When accessing friends directly, a server is running that tries to serve content at this URL. so it is necessary to resolve this problem at the server level. For example, I redirect all calls to / i.e. content is loaded first from / and then Angular already routes to the desired template

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question