角UI的路由器发送根URL 404

编程入门 行业动态 更新时间:2024-10-27 17:12:19
本文介绍了角UI的路由器发送根URL 404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个关于真气问题 UI路由器。一切正常,因为我想,所有不良网址发送到 404 状态。不过,即使我的默认状态是正确呈现当网址 /#/ , / 被重定向的URL到 / 404 / 。哪能服务器默认状态,以两个 / 和 /#/ ?

I am having an infuriating issue regarding ui-router. Everything works as I want, where all bad urls are sent to the 404 state. However, even though my default state is correctly rendered when the url is /#/, the url of / is redirected to /404/. How can I server the default state to both / and /#/?

app.js

MyApp.config( function ($stateProvider, $urlRouterProvider) { // For any unmatched url, send to 404 $urlRouterProvider.otherwise("/404/"); $stateProvider // Home (default) .state('default', { url: '/', resolve: { ... }, } });

任何帮助非常AP preciated。

Any help much appreciated.

推荐答案

我认为这将实现您的需求 -

I think this will accomplish your needs -

MyApp.config(function($stateProvider, $urlRouterProvider) { // the known route $urlRouterProvider.when('', '/'); // For any unmatched url, send to 404 $urlRouterProvider.otherwise('/404'); $stateProvider // Home (default) .state('default', { url: '/', resolve: { // ... } // .... }); });

我来所指向这个帖子。您可能需要使用常规的前pression来处理与数据路由。

I refered to this post. You may need to use a regular expression to handle routes with data.

相反的#在您的网址,你可以使用查询字符串太,并通过 $ stateParams 抓住它的状态。

Instead of the # in your URL you can use a query string too and grab it via $stateParams in a state.

下面是你如何做到这一点 -

Here is how you can do that -

// .... $stateProvider .state('default', { url: '/?data', templateUrl: 'templates/index.html', controller: 'defaultCtrl' })

然后你可以使用这个下面去家里用的数据 -

And then you can use this below to go to home with data -

var toStateData = { key1: 'value1', key2: 'value2' } $state.go('default', {data: JSON.stringify(toStateData)});

您不必在字符串化 $ stateParams 数据,但是这将允许用一个参数更多的选择。在 defaultCtrl 控制器就可以得到通过查询字符串这样的 -

You don't have to stringify the data in $stateParams but this will allow more options with one parameter. In the defaultCtrl controller you can get the passed query string like this -

var stateData = JSON.parse($stateParams.data); var key1 = stateData.key1; // ....

更多推荐

角UI的路由器发送根URL 404

本文发布于:2023-10-06 18:59:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1467620.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由器   UI   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!