Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

页面与ant锚点组件的问题 #287

Closed
marsDes opened this issue Nov 17, 2016 · 13 comments
Closed

页面与ant锚点组件的问题 #287

marsDes opened this issue Nov 17, 2016 · 13 comments
Labels

Comments

@marsDes
Copy link

marsDes commented Nov 17, 2016

http://localhost:8989/#/flightstatus?_k=gopn9y
在这个页面有个锚点 id="A" 触发后
地址栏的url会变成http://localhost:8989/#A
会导致页面刷新的时候报错
有人遇到这个问题吗?

@lincenying
Copy link

用hash模式, 就不用锚点, 这是共识

@marsDes
Copy link
Author

marsDes commented Nov 17, 2016

有没有办法实现这样的功能,
去除hash模式?

@lincenying
Copy link

用history模式.

@sorrycc
Copy link
Member

sorrycc commented Nov 17, 2016

拍脑袋想到两个方案:

  1. history 用 browserHistory,肯定就没这个问题了
  2. 锚点在 url 上用查询参数,比如 /#/flightstatus?anchor=A,然后通过 JavaScript 实现定位到 A 元素

@marsDes
Copy link
Author

marsDes commented Nov 17, 2016

@sorrycc 请问第一个方案的话在哪里修改呢?
在webpack.config.js没找到

@marsDes
Copy link
Author

marsDes commented Nov 17, 2016

感激!

试下第二个方案

@yuzhouisme
Copy link

这篇文章,值得学习!感觉有些地方DVA用的是ES7的写法,比如Dump Component,ES6跟ES7搞得很混淆。。

在 2016年11月17日,下午11:07,Mars notifications@github.com 写道:

感激!
修改history 方式解决。
相关的文档链接有点多没有细看。
现在试下第二个方案


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub #287 (comment), or mute the thread https://github.com/notifications/unsubscribe-auth/ACv7Uu9iYuqBB6TnaBGHXGRJpZFkxIUIks5q_G27gaJpZM4K1RFk.

@nikogu
Copy link
Member

nikogu commented Nov 22, 2016

@marsDes 问题是否解决?

@nikogu
Copy link
Member

nikogu commented Nov 22, 2016

先close了

@nikogu nikogu closed this as completed Nov 22, 2016
@marsDes
Copy link
Author

marsDes commented Nov 23, 2016

不好意思,刚看到
用了history配置
地址栏 http://localhost:8989/flightstatus#A
刷新 出现 Not found

看到issues有相关的,我先看一遍先
第二个方法还没实现。
@nikogu

@lincenying
Copy link

用history模式, 需要服务器或者后端的支持...
#180
看看这个issue

@zp1112
Copy link

zp1112 commented Mar 17, 2017

使用模拟锚点的形式完成锚点定位,不要直接使用href=#anchor的形式,需要拼接完整的地址url,在IE9下面也兼容,我是vue-router,原理是一样的,你看看。

toAnchor(anchor){
        const url = document.location.href.split('#');
        this.$router.push(`${url[1]}#${anchor}`);
      }
beforeRouteUpdate(to, from, next){
      if (to.hash !== '') {
        const id = to.hash.replace('#', '');
        const element = document.getElementById(id);
// 定位到锚点
        if (element) element.scrollIntoView();
      }
      next();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants