How to set Default page in Angular

痞子三分冷 提交于 2019-12-31 05:42:09

问题


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!



来源:https://stackoverflow.com/questions/26313790/how-to-set-default-page-in-angular

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!