0

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

<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.

When I hit F5 the page refreshes, but it STILL SHOWS the dokument route!

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)

How can I fix this?

chichi
  • 207
  • 1
  • 4
  • 13
  • you could use `window.onload=function(){$location.path("/")}` to switch to main view everytime when the page is loaded. If you want this function only on special views then add it to the controller of the view (you have to inject $location to your controller and you can use this only in your controller. Otherwise this cant work). – Matthias Gwiozda Jun 24 '17 at 12:40
  • Or if you want to use it outside of a controller you could just use: `history.pushState('', 'New Page Title', "/");` (Reference: https://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page) – Matthias Gwiozda Jun 24 '17 at 13:05
  • have you tried to put in your html index.html in deah a tag like ? – federico scamuzzi Jun 24 '17 at 13:21

1 Answers1

0

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('/');
        }
    });
});
FabioBranch
  • 175
  • 4
  • 19
chichi
  • 207
  • 1
  • 4
  • 13