typescript – 使用angular2 rc4将所有无效URL重定向到特定组件
发布时间:2020-12-17 17:58:35 所属栏目:安全 来源:网络整理
导读:我正在用“@ angular / router”编写一个angular2 rc4应用程序:“3.0.0-beta.2”. 现在我有两条路线,欢迎和帮助,我创建了另一条路线,将其他所有内容重新发送到欢迎组件. 这是我的routes.ts文件: import { provideRouter,RouterConfig } from "@angular/rou
我正在用“@ angular / router”编写一个angular2 rc4应用程序:“3.0.0-beta.2”.
现在我有两条路线,欢迎和帮助,我创建了另一条路线,将其他所有内容重新发送到欢迎组件. 这是我的routes.ts文件: import { provideRouter,RouterConfig } from "@angular/router"; import {WelcomeComponent} from "./welcome.component"; import {HelpComponent} from "./help.component"; export const routes:RouterConfig = [ { path: "",redirectTo: "welcome"},{ path: "welcome",component: WelcomeComponent },{ path: "help",component: HelpComponent} ]; export const APP_ROUTER_PROVIDERS = [ provideRouter(routes) ]; 我的服务器是GoLang,我已将其配置为所有无效的网址将重定向到index.html 所以现在如果我浏览例如:localhost / weclome2, EXCEPTION: Error: Uncaught (in promise): Error: Cannot match any routes: 'welcome2' VM8530:27 EXCEPTION: Error: Uncaught (in promise): Error: Cannot match any routes: 'welcome2'window.console.error @ VM8530:27BrowserDomAdapter.logError @ bundle.js:50349BrowserDomAdapter.logGroup @ bundle.js:50359ExceptionHandler.call @ bundle.js:11343(anonymous function) @ bundle.js:14458schedulerFn @ bundle.js:14747SafeSubscriber.__tryOrUnsub @ bundle.js:15377SafeSubscriber.next @ bundle.js:15326Subscriber._next @ bundle.js:15279Subscriber.next @ bundle.js:15243Subject.next @ bundle.js:14835EventEmitter.emit @ bundle.js:14735onError @ bundle.js:19058onHandleError @ bundle.js:19270ZoneDelegate.handleError @ bundle.js:5267Zone.runGuarded @ bundle.js:5173_loop_1 @ bundle.js:5427drainMicroTaskQueue @ bundle.js:5434ZoneTask.invoke @ bundle.js:5366 VM8530:27 STACKTRACE:window.console.error @ VM8530:27BrowserDomAdapter.logError @ bundle.js:50349ExceptionHandler.call @ bundle.js:11345(anonymous function) @ bundle.js:14458schedulerFn @ bundle.js:14747SafeSubscriber.__tryOrUnsub @ bundle.js:15377SafeSubscriber.next @ bundle.js:15326Subscriber._next @ bundle.js:15279Subscriber.next @ bundle.js:15243Subject.next @ bundle.js:14835EventEmitter.emit @ bundle.js:14735onError @ bundle.js:19058onHandleError @ bundle.js:19270ZoneDelegate.handleError @ bundle.js:5267Zone.runGuarded @ bundle.js:5173_loop_1 @ bundle.js:5427drainMicroTaskQueue @ bundle.js:5434ZoneTask.invoke @ bundle.js:5366 VM8530:27 Error: Uncaught (in promise): Error: Cannot match any routes: 'welcome2' at resolvePromise (bundle.js:5478) at bundle.js:5455 at ZoneDelegate.invoke (bundle.js:5263) at Object.onInvoke (bundle.js:19249) at ZoneDelegate.invoke (bundle.js:5262) at Zone.run (bundle.js:5156) at bundle.js:5511 at ZoneDelegate.invokeTask (bundle.js:5296) at Object.onInvokeTask (bundle.js:19240) at ZoneDelegate.invokeTask (bundle.js:5295)window.console.error @ VM8530:27BrowserDomAdapter.logError @ bundle.js:50349ExceptionHandler.call @ bundle.js:11346(anonymous function) @ bundle.js:14458schedulerFn @ bundle.js:14747SafeSubscriber.__tryOrUnsub @ bundle.js:15377SafeSubscriber.next @ bundle.js:15326Subscriber._next @ bundle.js:15279Subscriber.next @ bundle.js:15243Subject.next @ bundle.js:14835EventEmitter.emit @ bundle.js:14735onError @ bundle.js:19058onHandleError @ bundle.js:19270ZoneDelegate.handleError @ bundle.js:5267Zone.runGuarded @ bundle.js:5173_loop_1 @ bundle.js:5427drainMicroTaskQueue @ bundle.js:5434ZoneTask.invoke @ bundle.js:5366 VM8530:27 Unhandled Promise rejection: Cannot match any routes: 'welcome2' ; Zone: angular ; Task: Promise.then ; Value: Error: Cannot match any routes: 'welcome2'(…)window.console.error @ VM8530:27consoleError @ bundle.js:5401_loop_1 @ bundle.js:5430drainMicroTaskQueue @ bundle.js:5434ZoneTask.invoke @ bundle.js:5366 VM8530:27 Error: Uncaught (in promise): Error: Cannot match any routes: 'welcome2'(…)window.console.error @ VM8530:27consoleError @ bundle.js:5403_loop_1 @ bundle.js:5430drainMicroTaskQueue @ bundle.js:5434ZoneTask.invoke @ bundle.js:5366 我错过了什么? 谢谢! 更新 根据谷歌搜索,我发现了一些旧版本的angular2的回复,所以我尝试使用以下代码将它们采用到新版本: export const routes:RouterConfig = [ { path: "",redirectTo:"welcome",pathMatch:"full"},component: HelpComponent},{ path: "*",redirectTo:"welcome"} ]; 但结果完全一样. 解决方法
新路由器使用’**’而不是单个’*’
export const routes:RouterConfig = [ { path: "",{ path: "**",redirectTo:"welcome"} ]; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |