简体   繁体   English

AngularJS刷新页面(F5)取消路由

[英]Angularjs Refresh page (f5) cancel routing

I have this routing on my webpage: 我的网页上有以下路由:

app.config(function($routeProvider)
{
    $routeProvider
        .when("/",
            {
                //
            })
        .when("/DokumentRoute",
            {
                templateUrl : "static/routes/dokument.html",
                controller : "dokumentController"
            })
        .when("/MarkningarRoute",
            {
                templateUrl : "static/routes/markning.html",
                controller: "markningarController"
            })
        .otherwise(
            {
                templateUrl: "static/routes/pageNotFound.html",
                controller : "pageNotFoundController"
            });
});

When I refresh the page (F5) I want to cancel the routing, meaning I don't want to show anything within the ng-view tag 刷新页面(F5)时,我想取消路由,这意味着我不想在ng-view标签内显示任何内容

<div ng-view id="view"></div>

This is what happens now: 这就是现在发生的情况:

When I start the web page it shows no routing-page. 当我启动网页时,它没有显示路由页面。 I click on "dokument" and it routes to the dokument page, which shows in the ng-view tag. 我单击“ dokument”,它会路由到ng-view标签中显示的dokument页面。

When I hit F5 the page refreshes, but it STILL SHOWS the dokument route! 当我按F5键时,页面会刷新,但仍显示文档路径!

This is what I want: 这就是我要的:

I want the routing to cleared. 我希望清除路由。 I want the web site to look like when I first entered it. 我希望该网站在初次进入时看起来像。 (nothing showing in the ng-view tag) (ng-view标签中未显示任何内容)

How can I fix this? 我怎样才能解决这个问题?

If anyone is interested, this is how I solved it: 如果有人感兴趣,这就是我解决的方法:

app.run(function ($location, $rootScope) {

    $rootScope.$on('$routeChangeStart', function (event, next, current) {
        if (!current) {
            $location.path('/');
        }
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM