How to set Default page in Angular

2019-03-06 09:50发布

问题:

I am getting an error when I request the link with this URL: http://xxx:46630/ or with this http://crmbyzaid.azurewebsites.net/

But it is working good when I add '/index.html' with URL. Now I want to set the Default render of my partial page "app/dashboard/dashboard.html" when I request with just http://crmbyzaid.azurewebsites.net/

My code of config-route.js is

function routeConfigurator($routeProvider, routes) {

    routes.forEach(function (r) {
        $routeProvider.when(r.url, r.config);
    });
    $routeProvider.otherwise({ redirectTo: '/' });
}
function getRoutes() {
    return [
        {
            url: '/',
            config: {
                templateUrl: 'app/dashboard/dashboard.html',
                title: 'dashboard',
                settings: {
                    nav: 1,
                    content: '<i class="fa fa-dashboard"></i> Dashboard'
                }
            }
        }, {
            url: '/admin',
            config: {
                title: 'admin',
                templateUrl: 'app/admin/admin.html',
                settings: {
                    nav: 1,
                    content: '<i class="fa fa-lock"></i> Admin'
                }
            }
        }
]
}

回答1:

Since Azure is running on IIS, you need a web.config to tell it how to handle stuff.. This should solve your root-page:

<configuration>
    <system.webServer>
        <rewrite>
          <rules>
            <rule name="Main Rule" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Name the file web.config and save it to your web-root.

Hope that helps!