1

In my project the router is set up like this :

   myApp.component("rsapproot", {
        transclude: true,
        template: "<ng-transclude></ng-transclude>",
        $routeConfig: [
            { path: "/login", component: "rsapplogin", name: "Login" },
            { path: "/tenant", component: "rsapptenantid", name: "Tenant" },
            { path: "/my-dashboard", component: "rsappmyrdash", name: "MyDash" },
            { path: "/my-reports", component: "rsappmyreports", name: "AppReports"},
            { path: "/equipment-details/:type/:id", component: "rsequipmentdetails", name: "EquipmentDetails" },
            { path: "/my/resources", component: "rsappresourceslist", name: "AppResourceList" },

Now expected behaviour after F5 or when pasting URL is, respectively, having current path reloaded or navigating to the said path, instead the initial application path is loaded.

I know that in order to retain the page after reload app, a url representing the path should be given.

But that thing is already there and the paths respectively are all unique.

Then what am I missing ?

StrugglingCoder
  • 4,781
  • 16
  • 69
  • 103

1 Answers1

2

This needs to be handled on the server side. Here's an example that illustrates the current problem:

You load the app at its initial path / and then navigate to /login. When you refresh the page, your web browser then sends a GET request to http://yourdomain.com/login which (I'm assuming) does not not respond by sending your Angular app (index.html) to the client.

You need to configure your server to respond to GET requests for all of your specified Angular paths with your index.html. This is often done with a catch-all route /* instead of specifying each route individually.

AJ Funk
  • 3,099
  • 1
  • 16
  • 18
  • Does it mean for all possible routes the server will respond with appropriate templates that are to be loaded for that specific route ? But is not that what Angular Router is meant for ? I am a bit confused. – StrugglingCoder Mar 29 '17 at 10:01
  • 1
    Not quite. For example, `http://yourdomain.com` responds with your `index.html`. In order for `http://yourdomain.com/login` to work on refresh, your server also needs to respond with `index.html`. Once the client receives that file, the Angular Router can take over – AJ Funk Mar 29 '17 at 18:31