簡體   English   中英

深度路由無法按預期的ui路由器運行

[英]Deep Routing not working as expected ui-router

這是我的路由代碼,正如我在Internet上檢查的那樣,將html5Mode與requireBase一起使用應該可以解決此問題。 當我直接嘗試訪問localhost / index時 ,它說無法GET / login

app.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
    // Setting login page as default location for the App
    $urlRouterProvider.otherwise("/login");

    $stateProvider.state('root', {
        url: '/login',
        views: {
            "temp_app": {
                templateUrl: 'app.tpl.html'
            }
        }
    });
    $locationProvider.html5Mode({ enabled: true, requireBase: false });
});

這是一個網絡服務器問題,雖然您未指定哪種技術,但我還是在偷看另一個用IIS標記的問題,因此,如果您確實在使用IIS,則需要在Web.config包括一些<rewrite>規則。 。 requireBase: false也不是正確的方法,我們需要一個基礎。 觀察以下示例...

<head>
    <base href="/">
[...]

app.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {

    $locationProvider.html5Mode({
        enabled: true
    });
[...]

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

如果我的想法不對,並且您沒有使用IIS,請參見針對常見Web服務器的重寫解決方案,包括(以及IIS): ApacheNginxExpress- 如何:配置服務器以使用html5Mode

另外,請參閱$ location文檔以獲取更多信息,以及錯誤:HTML5模式下的$ location:nobase $ location需要存在標簽! 深入了解為什么我們需要以這種方式設置我們的應用程序

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM