Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 路径:“**&引用;对于未找到的页面_Angular_Angular2 Routing - Fatal编程技术网

Angular 路径:“**&引用;对于未找到的页面

Angular 路径:“**&引用;对于未找到的页面,angular,angular2-routing,Angular,Angular2 Routing,我正在使用angular 2中的路由和typescript 在mainindex.html中,我添加了,而不是,因为我的项目需要特殊路线,而且一切正常,但我有一些找不到页面的问题。这是我的app.route.ts的一部分: const appRoutes: Routes = [ { component: LaskComponent, path: "table_per" }, { component: LaskComponent, path: "table_per/:id" },

我正在使用angular 2中的路由和typescript

在main
index.html
中,我添加了
,而不是
,因为我的项目需要特殊路线,而且一切正常,但我有一些找不到页面的问题。这是我的
app.route.ts
的一部分:

const appRoutes: Routes = [
    { component: LaskComponent, path: "table_per" },
    { component: LaskComponent, path: "table_per/:id" },
    { component: DashboardComponent, path: "dashboard" },
    { component: LoginComponent, path: "login" },
    { path: "", pathMatch: "full", redirectTo: "login" },
    { component: HomeComponent, path: "home" },
    { component: NotFoundComponent, path: "not_found" },
    { path: "**", redirectTo: "not_found" },
];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
这是
NotFoundComponent

import { Component } from "@angular/core";
@Component({
    template: ' 
        <div class="container">
            <h1>Not found page</h1>
        </div>',
})
export class NotFoundComponent {};
启动我的项目我可以从3个部署开始:


这可能会解决您的问题:

import {APP_BASE_HREF} from '@angular/common';

@NgModule({
  declarations: [AppComponent],
  bootstrap: [AppComponent],
  imports: [BrowserModule, routing /* or RouterModule */], 
  providers: [{provide: APP_BASE_HREF, useValue : '/' }]
]); 

另请参见

您可以提供
APP_BASE_HREF
而不是
对不起,您能告诉我,当我在
localhost
中启动我的应用程序时,它的工作非常好,但是当我从服务器启动我的应用程序时:
10.10.0.1/object/go
我从我的组件中获取了一个找不到的页面,有什么问题吗?或者您的服务器不支持pushState,或者您需要为
(或与
APP_BASE_HREF
类似的路径)。在发布之前,我可以选择启动-/go或-/python。我不知道您所说的“我可以选择…”是什么意思
import {APP_BASE_HREF} from '@angular/common';

@NgModule({
  declarations: [AppComponent],
  bootstrap: [AppComponent],
  imports: [BrowserModule, routing /* or RouterModule */], 
  providers: [{provide: APP_BASE_HREF, useValue : '/' }]
]);