Skip to content

Commit c39aba6

Browse files
committed
Change dcc.Link for absolute paths (#782)
* Changed window.location for absolute paths * Added integration tests * Flaky test run 3.7
1 parent 3c7e8d4 commit c39aba6

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

packages/dash-core-components/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
99
- [#776](https://github.com/plotly/dash-core-components/pull/776) Update dcc.Link to set href as children if children not defined. Makes href a required prop as well.
1010
- [#767](https://github.com/plotly/dash-core-components/pull/767) Updated dcc.Link to respond to click modifiers, and added a target prop.
1111
- [#774](https://github.com/plotly/dash-core-components/pull/774) Fixed dcc.Location firing callbacks for wrong property.
12+
- [772](https://github.com/plotly/dash-core-components/pull/772) Modified dcc.Link to work with absolute paths if refresh=True.
1213

1314
## [1.8.1] -2020-02-27
1415
### Added

packages/dash-core-components/src/components/Link.react.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default class Link extends Component {
5454
// prevent anchor from updating location
5555
e.preventDefault();
5656
if (refresh) {
57-
window.location.pathname = href;
57+
window.location = href;
5858
} else {
5959
window.history.pushState({}, '', href);
6060
window.dispatchEvent(new CustomEvent('_dashprivate_pushstate'));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import pytest
2+
import dash
3+
from dash.dependencies import Input, Output
4+
import dash_core_components as dcc
5+
import dash_html_components as html
6+
7+
8+
@pytest.mark.DCC782
9+
def test_lipa001_path(dash_dcc):
10+
app = dash.Dash(__name__)
11+
app.layout = html.Div(
12+
[
13+
dcc.Link("Relative Path", id="link1", href="google.com"),
14+
dcc.Location(id="url", refresh=False),
15+
html.Div(id="content")
16+
]
17+
)
18+
@app.callback(Output("content", "children"), [Input("url", "pathname")])
19+
def display_children(children):
20+
return children
21+
22+
dash_dcc.start_server(app)
23+
24+
dash_dcc.wait_for_element('#link1').click()
25+
26+
dash_dcc.wait_for_text_to_equal("#content", "/google.com")
27+
28+
29+
@pytest.mark.DCC782
30+
def test_lipa002_path(dash_dcc):
31+
app = dash.Dash(__name__)
32+
app.layout = html.Div(
33+
[
34+
dcc.Link(children='Absolute Path', id="link1", href="https://google.com", refresh=True),
35+
dcc.Location(id="url", refresh=False)
36+
]
37+
)
38+
dash_dcc.start_server(app)
39+
40+
dash_dcc.wait_for_element('#link1').click()
41+
42+
location = dash_dcc.driver.execute_script(
43+
'''
44+
return window.location.href
45+
'''
46+
)
47+
48+
assert location == 'https://www.google.com/'

0 commit comments

Comments
 (0)