How to disable static url in angular ui-router?

2019-07-20 16:10发布

I have some two ui-router states in my angular application, which works fine, like this:

app.config(["$stateProvider",
    function($stateProvider){
        $stateProvider
            .state("settings", {
                url: "/settings",
                views: {
                    "secondMenu": {
                        templateUrl: "second_menu.html?parent=settings",
                        controller: "settingsController"
                    },
                    "thirdMenu": {
                        template: empty_template
                    }
                }
            })
            .state("cabinet", {
            url: "/cabinet",
            views: {
                "secondMenu": {
                    templateUrl: "second_menu.html?parent=cabinet",
                    controller: "cabinetController"
                },
                "thirdMenu": {
                    template: empty_template
                }
            }
        })

But only part of my menu i need work with angular. Other part of menu must go to static (not angular) url of my site, like this:

<ul>
    <li><a href="/static-url/">static-url</a></li>
    <li><a ui-sref="cabinet">cabinet angular url</a></li>
    <li><a ui-sref="settings">settings angular</a></li>
</ul>

And when i click on angular-urls - i get need information in my ng-view , but if after then i click on static-url - my url changing from /#/cabinet (for ex.) to /static-url/, but query to server does not exist. Page content saving as in cabinet angular url.

How I can disabling angular ui-router working on /static-url/ ?

1条回答
劳资没心,怎么记你
2楼-- · 2019-07-20 16:10

So for future lurkers, here's what you need to do. Just add this attribute to your static page's anchor tag:

target="_self"

Like this:

<ul>
    <li><a href="/static-url/" target="_self">static-url</a></li>
    <li><a ui-sref="cabinet">cabinet angular url</a></li>
    <li><a ui-sref="settings">settings angular</a></li>
</ul>
查看更多
登录 后发表回答