代码之家  ›  专栏  ›  技术社区  ›  José Manuel

共享主机中Angular2的路由

  •  0
  • José Manuel  · 技术社区  · 7 年前

    我在共享主机(1和1)中上载了一个带有angular2和symfony3的应用程序。

    这是网站: http://s714578534.mialojamiento.es

    它重定向到 http://s714578534.mialojamiento.es/inicio ,效果很好。

    问题是当我尝试直接访问 http://s714578534.mialojamiento.es/inicio , http://s714578534.mialojamiento.es/libros/1/Todos/Valoraci%C3%B3n , ... 网站未加载。

    指数html

    <!doctype html>
    <html lang="es">
    <head>
       <meta charset="utf-8">
       <title>Conectando Lectores</title>
       <base href="/">
       <meta name="description" content="Free Web tutorials">
       <meta name="keywords" content="Red Social, Literatura, Libros, Libro, Microcuento, Microcuentos, Autores, Autor, Autora, Lectura, Leer">
       <meta name="author" content="José Manuel Vázquez Crespo">
       <meta name="viewport" content="width=device-width, initial-scale=1">
       <link rel="icon" type="image/x-icon" href="favicon.ico">
    </head>
    <body>
       <app-root>Cargando...</app-root>
    </body>
    </html>
    

    应用程序。路由。ts

    const appRoutes: Routes = [
    // Ruta de inicio de la aplicación
    { path: '', redirectTo: 'inicio', pathMatch: 'full'},
    // Otras rutas
    { path: 'inicio', component: DefaultComponent },
    { path: 'login', component: LoginComponent },
    { path: 'login/:id', component: LoginComponent }, 
    { path: 'login/:email/:verificationKey', component: LoginComponent }, 
    { path: 'login/:id/:email/:verificationKey', component: LoginComponent }, 
    { path: 'registro', component: RegisterComponent },
    { path: 'perfil', component: PerfilComponent },
    { path: 'perfil/:username', component: PerfilComponent },
    { path: 'perfil/:username/:type', component: PerfilComponent },
    { path: 'mibiblioteca', component: LibraryComponent },
    { path: 'usuarios', component: UsuariosComponent },
    { path: 'mensajes', component: PrivateMessageComponent },
    { path: 'mensajes/:username', component: PrivateMessageComponent },
    { path: 'notificaciones', component: NotificationComponent },
    { path: 'politicaprivacidad', component: PoliticaPrivacidadComponent },
    { path: 'terminosycondiciones', component: TerminosyCondicionesComponent },
    { path: 'contacta', component: ContactaComponent },
    { path: 'noticias', component: NewsComponent },
    { path: 'noticias/:title', component: NewsComponent },
    // Books
    { path: 'libros', redirectTo: '/libros/1/Todos/Valoración', pathMatch: 'full' },
    { path: 'libros/:page/:genre/:order/:title', component: LibrosComponent }, 
    { path: 'libros/:page/:genre/:order', component: LibrosComponent },
    { path: 'libros/:page/:titulo', component: LibrosComponent },
    { path: 'libros/:titulo', component: VisualizarlibroComponent } 
    ];
    
    export const appRoutingProviders: any[] = [];
    export const routing: ModuleWithProviders = 
    RouterModule.forRoot(appRoutes);
    

    有什么解决方案吗?谢谢

    3 回复  |  直到 7 年前
        1
  •  2
  •   habibun    7 年前

    试着改变你的。htacces公司

    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.html [QSA,L]
    
        2
  •  2
  •   Ramiro Uvalle    7 年前

    尝试更改此行

    RouterModule.forRoot(appRoutes);
    

    为了这个

    RouterModule.forRoot(appRoutes, { useHash: true });
    
        3
  •  0
  •   albert    7 年前

    Symfony将捕获与任何文件不匹配的任何URL。

    将symfony移动到另一个子域:

    http://[angular].mialojamiento.es

    http://[symfony api]。米阿洛贾米恩托。锿

    您也可以使用子文件夹:

    http://[yourid].mialojamiento.es/api/app.php <--symfony公司

    http://[yourid].mialojamiento.es/ <--有棱角的