Warning: file_put_contents(/datas/wwwroot/jiajiahui/core/caches/caches_template/2/default/show.php): failed to open stream: Permission denied in /datas/wwwroot/jiajiahui/core/libraries/classes/template_cache.class.php on line 55

Warning: chmod(): Operation not permitted in /datas/wwwroot/jiajiahui/core/libraries/classes/template_cache.class.php on line 56
刷新页面 - 源码之家

刷新页面

问题描述:

我所有,刷新页面

时Angular2路由器的问题我有一个很常见的问题,但我没有找到解决办法,真正需要你的这一个帮助。

我在apache服务器上有一个angular2应用程序,并且在延迟加载的模块中存在路由器问题。

我有一个根模块,这是他的路由器文件:

import { NgModule }    from '@angular/core'; 
import { RouterModule, Routes } from '@angular/router'; 

// App Components 
import { AppComponent } from './app.component'; 
import { LoginComponent } from './auth/login.component'; 


const ROUTES: Routes = [ 
    { path: '', redirectTo: '/home', pathMatch: 'full' }, 
    { path: 'home', 
     loadChildren: 'dist/home/home.module.js#HomeModule' 
    } 
    { 
     path: 'childapp', 
     loadChildren: 'dist/childapp/childapp.module.js#ChildappModule' 

    }, 
    { 
     path: 'login', 
     component: LoginComponent 
    }, 
    { path: '**', redirectTo: '/home'} 
]; 

@NgModule({ 
    imports: [ RouterModule.forRoot(ROUTES) ], 
    exports: [ RouterModule ] 
}) 
export class RoutingModule {} 

这里是一个子单元的路由为例:

import { NgModule }    from '@angular/core'; 
import { RouterModule, Routes } from '@angular/router'; 
import { ModuleWithProviders } from "@angular/core"; 

import { ChildappComponent} from './childapp.component'; 
import { Sub1Component} from './sub1/Sub1.component'; 
import { Sub2Component} from './sub2/Sub2.component'; 

const routes = [ 
    { 
     path: "", 
     component: ChildappComponent, 

     children: [ 
      {path: "sub2", 
      component: Sub2Component}, 
      {path: "", 
      component: Sub1Component}, 
     ] 
    }, 

]; 

@NgModule({ 
    imports: [ RouterModule.forChild(routes) ], 
    exports: [ RouterModule ] 
}) 
export class LocobookRoutingModule {} 

当我点击链接,应有尽有没问题。

当我刷新“http://mywebsite.com/app/home”或“http://mywebsite.com/app/childapp”时,一切正常。

但是,当我尝试刷新“http://mywebsite.com/app/childapp/sub2”时,页面不显示。 如果有帮助,这是我的.htacces文件:

RewriteEngine on 

# if a directory or a file exists, use it directly 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# otherwise forward it to index.php 
RewriteRule . index.php 

非常感谢您对这个帮助。

我找到了解决我的问题的方法。

因为我使用的Apache和PHP,我可以很容易地指定一个绝对在我的index.php文件:

<base href="<?= "http://".$_SERVER['HTTP_HOST'].str_replace("index.php", "", $_SERVER['SCRIPT_NAME']); ?>"> 

我希望这会帮助别人!