路线不起作用我的代码有什么问题

时间:2019-06-24 12:39:16

标签: angular routes

我的app-routing.module.ts中有这条路线,它缺少一些东西,因为 当我转到此页面

  

https://angular-v4-dot-unique-yew-244216.appspot.com/search

我遇到错误,但是当我在这里工作时

  

https://angular-v4-dot-unique-yew-244216.appspot.com

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

import { SearchBooksComponent } from './search-books/search-books.component';

const routes: Routes = [
  {
    path: '',
    redirectTo: '/search',
    pathMatch: 'full'
  },
  {
    path: 'search',
    component: SearchBooksComponent
  }
];

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

路线怎么了?

这是我的app.yaml

runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /
  static_files: dist/index.html
  upload: dist/index.html
- url: /
  static_dir: dist

2 个答案:

答案 0 :(得分:1)

您应该重定向到class Int { private int wrapped; public Int(int wrapped) { this.wrapped = wrapped; } @Override public String toString() { return Integer.toString(wrapped); } public Int plus(Int other) { int sum = this.wrapped + other.wrapped; return new Int(sum); } } 而不是search

/search

仅当两条路线发生冲突时(例如const routes: Routes = [ { path: '', redirectTo: 'search', pathMatch: 'full' }, { path: 'search', component: SearchBooksComponent } ]; search),路线顺序才重要。 **将同时符合两条路线,并且第一个获胜。

您可以使用this之类的哈希定位策略。 此问题中也说明了路径定位策略。

答案 1 :(得分:0)

我们设置路线的顺序至关重要。尝试这个!。 最后设置默认路由。

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { SearchBooksComponent } from './search-books/search-books.component';

const routes: Routes = [
 { path: 'search', component: SearchBooksComponent },
 { path: '', redirectTo: 'search',pathMatch: 'full'}
];

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